浏览器如何解释HTTP状态代码为302但状态消息为Moved Permanently的响应?

时间:2014-07-09 22:39:02

标签: jquery ajax http-status-code-301 http-status-codes http-status-code-302

似乎RSA Cleartrust强制要求" 302永久移动"响应未经身份验证或会话过期的客户端。是否应该期望Chrome或IE10 +将此视为301 Moved Permanently,或者302 Moved暂时?我会想到后者,但我的jQuery 302处理被忽略,而是观察到301行为。

示例Fiddler检查客户端环境中的响应:

HTTP/1.1 302 Moved Permanently
Cache-Control: private
Content-Length: 0
Content-Type: text/html
Location: https://client.com/pub/logon.asp
Set-Cookie: ACTEWDSESSION=%20; domain=.client.com; path=/; HttpOnly
Set-Cookie: CTEWDSESSION=AAAAAgABAEBTlSKXkrdcxFyQIFJ7G2bEaIynGWXBmQGql%2BFy9plQ%2F3ofUQI2h3RNZWHdaFA%2BIi2zYuKAsxekzATPRv%2BgjtBl; domain=.client.com; path=/; HttpOnly
Set-Cookie: ACTEWDSESSION=aHR0cDovL2N2bS5pbnNpZGUudXBzLmNvbTo4MC9NVkMvYXBpL3NoaXBtZW50cy9leHBhbmRlZC83MDY4Nw%3D%3D; domain=.client.com; path=/; HttpOnly
SAMEORIGIN: DENY
X-Powered-By: ASP.NET
Access-Control-Allow-Methods: POST, GET, HEAD, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Authorization, Origin, Content-Type, Accept
Date: Mon, 07 Jul 2014 16:03:03 GMT

AJAX连线:

$.ajax({
                        url: url.replace(/{id}/g, id).replace(/{custId}/g, custId),
                        type: 'GET',
                        statusCode: {
                            301: ajax301_302Handling,
                            302: ajax301_302Handling,
                        }
                    }).done(function (data) {
                        debugger;
                        if (typeof renderDetails == 'function') {
                            oTable.fnOpen(nTr, renderDetails(data, id), 'details');
                        }
                        if (typeof renderDetailsComplete == 'function') {
                            renderDetailsComplete(id, custId, data);
                        }
                    });

1 个答案:

答案 0 :(得分:2)

浏览器和其他客户端应该只关心状态代码编号本身,而不是字符串。

如果有Location标题,XMLHttpRequest将遵循该标题。