CORS POST never occurs, even with successful OPTIONS preflight.
See original GitHub issueI have the following set up to POST to a different domain:
fetch(params.url, params.options)
.then(this._errorHandler)
.then(response => {
statusCode = response.status;
return response.json();
})
.then(result => {
result.statusCode = statusCode;
return Promise.resolve(result);
});
where my options look like:
{
body: JSON.stringify(requestBody),
credentials: 'same-origin',
mode: 'cors',
headers: {'Accept': 'application/json', 'Content-Type': 'application/json'},
method: 'POST'
}
When I am creating a POST request (that requires CORS), the OPTIONS preflight returns as a 200 with the correct headers, but the fetch
never actually does the POST request. Is there something I need to add to the options, or handle in another manner? I couldn’t find another issue or documentation related to this specific problem.
Edit: Yes, there is actually a properly set-up server with CORS enabled and working in other xhr requests.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Chapter 4. Handling preflight requests - CORS in Action
The CORS preflight request prevents unauthorized API requests from ever ... This means that even before CORS, clients could use the OPTIONS method...
Read more >CORS: preflight passes, main request completes w/200, but ...
In both the server logs and the js console, I can see that the preflight OPTIONS request succeeds. Then, the main request also...
Read more >4 Ways to Reduce CORS Preflight Time in Web Apps
If the browser finds the response, it won't send the Preflight request to the server, and instead, it uses the cached response. The...
Read more >CORS FAQ - cors-errors.info
For a preflight this must be OPTIONS . -H adds a request header. The values of the three headers will need changing to...
Read more >Reason: CORS preflight channel did not succeed - HTTP | MDN
Make sure your code only preflights once per connection. The preflight request suffered any kind of networking error that might ordinarily occur ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Does the request go through or does it just not show up in Chrome’s dev tools? I’m having the same exact issue and found this chromium issue: https://bugs.chromium.org/p/chromium/issues/detail?id=457484
Basically all fetch API requests with preflight end up in the Network -> Other tab
it was exactly the case for me in Chrome 🙈