HTTP preflight (OPTIONS) request fails in IE only(HTTP 预检 (OPTIONS) 请求仅在 IE 中失败)
问题描述
我尝试向我的 REST API 发出 POST 请求.这是代码片段(使用 AngularJS):
$http({方法:'POST',网址:网址,数据:reqBody,标题:{内容类型":应用程序/json"}}).then(函数(响应){...}).catch(函数 (错误) {...});
根据
问题是,HTTP 选项响应包含浏览器处理实际 HTTP 请求所需的一切.
我找到了所有这些混乱的原因.
API 服务和网站位于同一个域中,但在不同的端口上.具体来说,API 服务位于:
<块引用>myDomain.com/apiService
网站位于:
<块引用>myDomain.com:44443/webSite
因此,当网络浏览器从以下位置初始化调用时:
myDomain.com:44443/webSite/page1
到:
myDomain.com/apiService/service1
由于 CORS,Internet Explorer 阻止了调用.出于某种原因,Chrome 在这方面没有那么严格,因为它成功地调用了 API.
为了使其在 Internet Explorer 中运行,我将网站移至与 API 相同的端口:
<块引用>myDomain.com/apiService
myDomain.com/webSite
I trying to make a POST request to my REST API. Here is the code snippet (using AngularJS):
$http({
method: 'POST',
url: url,
data: reqBody,
headers: {
'content-type': 'application/json'
}
})
.then(function (response) {...})
.catch(function (error) {...});
According to this article, because of the HTTP header
'content-type': 'application/json'
browser concludes that it will have to make an "not-simple" HTTP request which requires handshake with a server (HTTP options request will be sent before actual HTTP request).
Chrome handles the request like a charm, but IE (11 in my case) fails with the following messages:
The thing is, HTTP options response contains everything the browser needs to proceed with the actual HTTP request.
I found the reason for all that mess.
The API service and the website were located on the same domain, but on different ports. To be specific, the API service was located on:
myDomain.com/apiService
and the website was located on:
myDomain.com:44443/webSite
Thus, when the web browser was initializing the call from:
myDomain.com:44443/webSite/page1
to:
myDomain.com/apiService/service1
Internet Explorer was blocking the call because of the CORS. For some reason, Chrome was less strict in that matter, because it succeeded to make the call to the API.
To make it work in Internet Explorer, I moved the website to the same port as the API:
myDomain.com/apiService
myDomain.com/webSite
这篇关于HTTP 预检 (OPTIONS) 请求仅在 IE 中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:HTTP 预检 (OPTIONS) 请求仅在 IE 中失败


- Flexslider 箭头未正确显示 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Fetch API 如何获取响应体? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01