是否有可能为XHR HEAD请求不进行重定向(301 302) [英] Is it possible for XHR HEAD requests to not follow redirects (301 302)

查看:603
本文介绍了是否有可能为XHR HEAD请求不进行重定向(301 302)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时可以发送一个XHR HTTP HEAD请求,只获得第一个请求头的响应,而不是自动跟随301,302像重定向?我只关心在得到URL的新位置。例如:

Is it possible to send an xhr HTTP HEAD request to only get header response for the first request and not automatically follow 301, 302 like redirects? I'm only interested in getting the new location of the url. Example:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(data) {
    if (xhr.readyState == 4) {
        if (xhr.status == 301 || xhr.status == 302) {
            // Get new location url don't GET it
        }
    }
};
xhr.open('HEAD', url, true);
xhr.send();

<一个href="http://www.w3.org/TR/XMLHtt$p$pquest/#infrastructure-for-the-send-method">http://www.w3.org/TR/XMLHtt$p$pquest/#infrastructure-for-the-send-method似乎指定的请求应遵循,是有没有办法制止?

http://www.w3.org/TR/XMLHttpRequest/#infrastructure-for-the-send-method seems to specify that requests should be followed, is there a way to stop this?

推荐答案

没有,这是不外露的行为就可以停止。

There isn't, this isn't exposed behavior you can stop.

这是因为您链接的规范已经的,指定的行为是XmlHtt prequest应的透明的执行重定向...在幕后遗憾的是,并没有一种方法可以prevent。

It's because of the spec you linked already, the specified behavior is that XmlHttpRequest should transparently follow redirects...under the covers unfortunately, and not in a way you can prevent.

这是这种方式,试图让事情变得更容易,如果资源动,等...但是当它的设计和规范布局,所有这些重定向服务并不在那里。实在是没有任何其他行为或能力prevent它有着强烈的需求,我想尽可能多重定向打网络不是我们将看到的能力增加,但谁知道,当每个浏览器都将支持它。

It's this way to try and make things easier, if resources move, etc...but when it was designed and the spec laid out, all these redirection services weren't out there. There just wasn't a strong need for any other behavior or ability to prevent it, I think with as many redirects hitting the web not we'll see the ability added, but who knows when every browser would support it.

这篇关于是否有可能为XHR HEAD请求不进行重定向(301 302)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆