question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CORS POST never occurs, even with successful OPTIONS preflight.

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

20reactions
neurosnapcommented, Aug 10, 2016

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

7reactions
mistadikaycommented, Dec 15, 2016

Basically all fetch API requests with preflight end up in the Network -> Other tab

it was exactly the case for me in Chrome 🙈

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found