2017-10-19 92 views
-4

请问fetch是否遵循HTTP 30x重定向?WebAPI获取是否遵循重定向?

+1

按照[规格](https://fetch.spec.whatwg.org/#http-redirect-fetch),是的。 – Amy

+2

取决于您是否将其配置为:https://developer.mozilla.org/en-US/docs/Web/API/Request/Request – deceze

回答

1

是的。 Check this

检查响应是否来自重定向的请求,如 就像在Response对象上检查这个标志一样简单。

if (response.redirected) { 
    //... 
} 

您可以禁用它:

fetch("awesome-picture.jpg", { redirect: "error" }).then(function(response) { 
    //some stuff 
}).then(function(imageBlob) { 
    //some other stuff 
});