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 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.
Share Improve this question asked Aug 21, 2017 at 8:22 altgov3enaltgov3en 1,2062 gold badges19 silver badges36 bronze badges 3- Are the headers present in both the POST and OPTIONS requests? – Sergiu Paraschiv Commented Aug 21, 2017 at 8:24
- @SergiuParaschiv I really can't tell if the headers present in IE POST request, because it never get there. But, I checked Chrome POST headers and they are in place (POST screenshot in Chrome). – altgov3en Commented Aug 21, 2017 at 9:03
- In my case I'm on IE11 (windows 10 home edition) and yes, all the OPTIONS request with an url "long" (concatenation of different kind of search params) fail. If I remove the search params (leaving getAll standard) the OPTIONS request (before the GET) works. So it's due to the length of URL? why? And how can I fix this stupid problem? Thanks in advance. – Domenico Commented Aug 27, 2019 at 15:31
2 Answers
Reset to default 3You could add sites to Trusted zone in IE settings and set "Access data sources across domains" to Enable (not Prompt):
It works not only for IE 9, but 10+ as well.
More on this: https://www.webdavsystem./ajax/programming/cross_origin_requests
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./apiService
and the website was located on:
myDomain.:44443/webSite
Thus, when the web browser was initializing the call from:
myDomain.:44443/webSite/page1
to:
myDomain./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./apiService
myDomain./webSite