JavaScript CORS Post Request在服务器端有空参数

时间:2013-03-19 14:36:45

标签: javascript http post http-headers cors

当我想向我的服务器发送POST请求时,它可以工作,但参数为空。在stackoverflow的另一个主题中,我读到它可能是标题的问题。还尝试了不同的浏览器,有时也可以。 这些是我在服务器端设置的标题:

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

当我尝试在客户端添加标头时,请求也总是变成一个options-request。请帮忙!!提前感谢所有答案!

This is the screenshot of the options-request:!

1 个答案:

答案 0 :(得分:2)

OPTIONS请求是用于确认服务器将接受实际请求的飞行前请求 - 这是CORS的一部分。

一旦OPTIONS请求得到响应(并假设响应显示“继续”),那么将发送实际的POST。数据应与此POST一起发送 - 而不是与OPTIONS请求一起发送。