Is it possible for XHR HEAD requests to not follow redirects (301 302)

后端 未结 4 1321
面向向阳花
面向向阳花 2020-11-30 07:48

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

4条回答
  •  既然无缘
    2020-11-30 08:20

    The W3C specification requires that redirects are followed automatically, as @Nick suggested in the other answer. However a property to disable redirects is being considered by the W3C for a future version of this specification:

    This specification does not include the following features which are being considered for a future version of this specification:

    • load event and onload attribute;
    • error event and onerror attribute;
    • progress event and onprogress attribute;
    • abort event and onabort attribute;
    • Timers have been suggested, perhaps an ontimeout attribute;
    • Property to disable following redirects;
    • responseXML for text/html documents;
    • Cross-site XMLHttpRequest;
    • responseBody to deal with byte streams;
    • overrideMimeType to fix up MIME types;
    • getRequestHeader() and removeRequestHeader().

    However, I wouldn't hold my breath until this is implemented by all browsers. You may want to use a server-side proxy to handle this. Simply write a short script to do a HEAD request in your favourite server-side language/framework, and then use Ajax to query this service. You would also be able to do requests to third-party domains through the proxy as a positive side-effect.

提交回复
热议问题