ada91
ada91

Reputation: 828

JavaScript CORS Post Request has empty parameters on the server side

When I want to sent a POST request to my server it works, but the parameters are empty. In another topic on stackoverflow, I read that it could be a problem with the headers. Also also tried it with different browsers and sometimes it works. These are the headers I set on the serverside:

headers['Access-Control-Allow-Origin'] = 'http://localhost:8080'
headers['X-Frame-Options'] = 'http://localhost:8080'
headers['Access-Control-Allow-Credentials']= 'true'
headers['Access-Control-Allow-Headers']= 'origin, content-type, content-length, accept, accept-language, accept-encoding'

In the attached Screemshot you can see the client headers

When I try to add headers on the client side the request also always turns into a options-request. Please help!! Thanks for all answers in advance!

This is the screenshot of the options-request:!

Upvotes: 2

Views: 1607

Answers (1)

Fenton
Fenton

Reputation: 250892

The OPTIONS request is the pre-flight request that is used to confirm that the server will accept the actual request - this is part of CORS.

Once the OPTIONS request gets a response (and assuming the response says "go ahead") then the actual POST will be sent. The data should be sent along with this POST - not with the OPTIONS request.

Upvotes: 2

Related Questions