[英]jQuery - ajax - post - json request - doesn't have post body in some URL
I've been stuck at this for a while now. 我已经为此停留了一段时间。 I have ajax request here:
我在这里有ajax请求:
$.ajax({
url: UPDATE_USER_INFO_URL ,
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify({user:'user'}),
success: function (data, textStatus) {
if(data["statusCode"] && data["statusCode"] == 1) {
_callback(1,data);
}
else {
_callback(0,data);
}
},
error: function (jqXHR, textStatus){
_callback(0, {});
}
});
If I set UPDATE_USER_INFO_URL
to a specific URL, fiddler show nothing in the body. 如果我将
UPDATE_USER_INFO_URL
设置为特定的URL,则提琴手在正文中什么也不显示。 If I set UPDATE_USER_INFO_URL
to something else (even invalid URL), it does put {user:'user'}
in the body in fiddler. 如果我将
UPDATE_USER_INFO_URL
设置为其他内容(甚至是无效的URL),它也会将{user:'user'}
放在提琴手的正文中。
With original UPDATE_USER_INFO_URL: 使用原始的UPDATE_USER_INFO_URL:
POST http://10.35.50.26:8080/SelfServiceWs/user/session/upduserinfo HTTP/1.1
Accept: application/json, text/javascript, ; q=0.01
Content-Type: application/json
X-Requested-With: XMLHttpRequest
Referer: http://10.35.50.26:8080/SelfService/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: 10.35.50.26:8080
Connection: Keep-Alive
Pragma: no-cache
Cookie: JSESSIONID=0BF9D9CCCE9030E60AB0BCE5F6562CD8
Authorization: Negotiate TlRMTVNTUAABAAAAl4II4gAAAAAAAAAAAAAAAAAAAAAGAbAdAAAADw==
Content-Length: 0
Chage url to /SelfServiceWs/abcdef 将网址转到/ SelfServiceWs / abcdef
POST http://10.35.50.26:8080/SelfServiceWs/abcdef HTTP/1.1
Accept: application/json, text/javascript; q=0.01
Content-Type: application/json
X-Requested-With: XMLHttpRequest
Referer: http://10.35.50.26:8080/SelfService/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: 10.35.50.26:8080
Content-Length: 15
Connection: Keep-Alive
Pragma: no-cache
Cookie: JSESSIONID=9E79779805579A7964E03AAD76DF043B
{"user":"user"}
I have many other ajax calls, all are working as expected. 我还有许多其他的ajax调用,它们都按预期工作。
It must be little thing that I am missing. 我想必一定是小事。
I figured this out. 我想通了。
I have an authentication servlet filter to url /user/ssoauth, unexpectedly (to me), it made eveything call to URL under /user path (including /user/session/upduserinfo) to send out Authorization header. 我有一个对URL / user / ssoauth进行身份验证的servlet过滤器,这对我来说是意外的,它对/ user路径(包括/ user / session / upduserinfo)下的URL进行了遍历调用,以发出Authorization标头。 Moved filter to /user/auth/ssoauth stop client to send authorization header when calling user/session/upduserinfo and fix the problem.
将过滤器移至/ user / auth / ssoauth停止客户端,以在调用user / session / upduserinfo时发送授权标头并解决此问题。
<filter-mapping>
<filter-name>SecurityFilter</filter-name>
<url-pattern>/user/ssoauth</url-pattern>
</filter-mapping>
cause every client call to URL after /user to send Authorization header. 使/ user之后的每个客户端对URL的调用都发送Authorization标头。
I learned something new today! 我今天学了些新东西!
尝试这个
data: JSON.stringify({'user':'user'}),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.