在有角度的HttpClient上下文中什么是冷观测 [英] What is cold observable in context of angular HttpClient

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

问题描述

虽然使用angular的angular HttpClient,但我知道HttpClient post方法使用了冷可观察的方法,将进行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冷可观察性表示它将保留所有序列直到结尾,并在订阅时将其全部触发.

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

它将如何对服务器进行两次单独的调用以发布数据.

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

推荐答案

我不认为此行为是由于使用可观察对象引起的.

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

相反,我怀疑浏览器正在与服务器作为握手"发出飞行前OPTIONS请求,以确定是否理解CORS协议.这先于POST请求,这可能就是为什么您两次调用服务器以发布数据的原因.

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆