【发布时间】:2018-09-30 11:12:50
【问题描述】:
基本上,我有一些 jQuery 试图将一些 JSON 数据发布到服务器。这是我发送时 Firefox 显示的标题。但是,如果我使用 Firefox 的“编辑并重新发送”功能,我可以强制它正确发送。如何更改我的代码以强制使用我想要的标题?我已经在服务器上启用了 cors,如果只有标头正确,我已经完成了使它工作所需的一切。
这是我的代码,后面是标题:
$.ajax({
url: "http://localhost:8080/users/login",
method: 'POST',
cors: true,
data: dat,
headers: {
"Accept": 'application/json'
},
dataType: "application/json",
success: function (response) {
alert('YAY');
},
failure: function (response) {
alert('Error', 'Invalid Credentials');
}
});
失败(通过代码发送)
Accept:text/html,application/xhtml+xm…plication/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Connection: keep-alive
Content-Length:31
Content-Type: application/x-www-form-urlencoded
Host: localhost:8080
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/59.0
有效(在 FireFox 中手动编辑标题)
Accept: application/json
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 41
Content-Type: application/json
Host: localhost:8080
Pragma: no-cache
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
【问题讨论】:
标签: jquery json post request http-headers