简体   繁体   English

获取重定向 url 而不关注

[英]Get redirect url without follow

Is there a way to get final redirect url without following it with Fetch API ?有没有办法在不使用Fetch API
Example:例子:
http://some.link/1 redirects to http://some.link/2 http://some.link/1重定向到http://some.link/2

fetch('http://some.link/1', someParams) => get ' http://some.link/2 ' url without request to it. fetch('http://some.link/1', someParams) => get ' http://some.link/2 ' url 没有请求它。

Yes, you can use the response.url property:是的,您可以使用response.url属性:

fetch('http://some.link/1').then(function(response) {
  console.log(response.url); // Final URL after redirections
});

The url read-only property of the Response interface contains the URL of the response. Response 接口的 url 只读属性包含响应的 URL。 The value of the url property will be the final URL obtained after any redirects. url 属性的值将是任何重定向后获得的最终 URL。

However, this will only work if the initial and all the URLs of the redirection chain have same origin.但是,这仅在重定向链的初始 URL 和所有 URL 具有相同来源时才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM