DEV Community

Discussion on: Why is my browser sending an OPTIONS HTTP request instead of POST?

Collapse
 
manangouhari profile image
Manan Gouhari

but how do we solve this?

Collapse
 
bellola profile image
Luis Bello

I solved it by doing what he said.

npm install cors

var cors = require('cors')

app.use(cors())

Afterwards I was able to make POST requests

Collapse
 
atikaakmal profile image
atikaakmal

Hi, I am doing the same things but still did not resolve this issue. could you please tell what i can do to resolve this errro.

Collapse
 
dreadfulcode profile image
ƊŗęДdϝul Ȼʘɗɇ • Edited

The most overlooked solution is to avoid preflight requests altogether. Send simple form data (application/x-www-form-urlencoded or multipart/form-data). As nice as JSON is to work with, it is best to send over flattened values when possible.

JSON and other types not in the above are complex requests, and all will have the pre-flight request.