本文介绍了在 Angular HttpClient 的上下文中什么是冷可观察的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 angular 的 HttpClient 时,我知道 HttpClient post 方法使用冷 observable 并将进行 2 个单独的调用以将数据发布到服务器.此外,除非您不订阅 post 方法它不会将数据发布到服务器.

While using angular HttpClient of angular I got to know that HttpClient post method used cold observable and will make 2 separate calls to post data to the server.And also unless you will not subscribe the post method it will not post data to the server.

尽管 Rxjs 冷 observable 表示它将保留所有序列直到结束并在订阅时触发所有序列.

Although, Rxjs cold observable says it will hold all the sequence until the the end and fire all when it subscribed.

它将如何向服务器发出 2 个单独的调用以发布数据.

How it will make 2 separate call to server to post data.

推荐答案

我不认为这种行为是由使用 observables 引起的.

I don't believe that this behavior is caused by the use of observables.

相反,我怀疑浏览器发出飞行前 OPTIONS 请求作为与服务器的握手",以确定是否理解 CORS 协议.这在 POST 请求之前,并且可能是您收到 2 次调用服务器以发布数据的原因.

Rather I suspect that the browser is issuing a pre-flight OPTIONS request as a 'handshake' with the server to determine whether the CORS protocol is understood. This precedes the POST request and is possibly why you get 2 calls to the server to post data.

这篇关于在 Angular HttpClient 的上下文中什么是冷可观察的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:49