Angular HTTP: Status -1 and CORS

前端 未结 2 2008
鱼传尺愫
鱼传尺愫 2020-12-11 20:02

In our angular application sometimes we get http status -1 returned to us. The status -1 happens on a popup that is closed, so the user isn\'t affected by it, just our logs.

2条回答
  •  星月不相逢
    2020-12-11 20:28

    In my experience, the most common cause of status of a -1, is that the browser blocked the response because of a violation of Same Origin Policy.

    For security reasons, browsers restrict cross-origin HTTP requests initiated from within scripts. For example, XMLHttpRequest and Fetch follow the same-origin policy. So, a web application using XMLHttpRequest or Fetch could only make HTTP requests to its own domain. To improve web applications, developers asked browser vendors to allow cross-domain requests.

    The Cross-Origin Resource Sharing (CORS) mechanism gives web servers cross-domain access controls, which enable secure cross-domain data transfers. Modern browsers use CORS in an API container - such as XMLHttpRequest or Fetch - to mitigate risks of cross-origin HTTP requests.

    See Use CORS to allow cross-origin access.

提交回复
热议问题