gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 16:34:17 25 4
gpt4 key购买 nike

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

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

当我尝试在客户端添加 header 时,请求也总是变成选项请求。请帮忙!!提前感谢所有答案!

This is the screenshot of the options-request:!

最佳答案

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

一旦 OPTIONS 请求得到响应(假设响应说“继续”),就会发送实际的 POST。数据应与此 POST 一起发送 - 而不是与 OPTIONS 请求一起发送。

关于JavaScript CORS Post Request 在服务器端有空参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15502419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com