簡體   English   中英

如何使用JavaScript重定向URL鏈接

[英]How to get redirecting url link with JavaScript

假設一個類似www.example.com/random的網站將您重定向到隨機網站,我想獲取它重定向到的鏈接

我只是在尋找JavaScript中http://redirectdetective.com/的工作方式

我確定答案已經遍地開花,但是我不確定會叫什么,所以我不知道要用谷歌搜索什么,而且我找到的所有答案都是用我無法翻譯的不同語言編寫的, 提前致謝!

它正在獲取URL,並且每次響應是另一個重定向時,它都會獲取新的URL,依此類推,直到最終到達未重定向的URL。

粗略地講:可​​能使用AJAX將GET請求發送到URL,並在收到301 REDIRECT后,查看發送回以重定向到的新URL。

http://redirectdetective.com/上,我嘗試了一個說http://blogspot.com/的網址

首先,我在這里curl縮

curl http://blogspot.com/ --verbose

它給了我很多細節,其中有趣的部分是HTTP RESPONSE HEADER

< HTTP/1.1 301 Moved Permanently
< Location: http://www.blogger.com/
< Content-Type: text/html; charset=UTF-8
< X-Content-Type-Options: nosniff
< Date: Tue, 13 Mar 2018 16:39:03 GMT
< Expires: Thu, 12 Apr 2018 16:39:03 GMT
< Server: sffe
< Content-Length: 220
< X-XSS-Protection: 1; mode=block
< Cache-Control: public, max-age=2592000
< Age: 1681577

然后使用Location參數再試一次

curl http://www.blogger.com/ --verbose

給我響應頭

< HTTP/1.1 302 Moved Temporarily
< P3P: CP="This is not a P3P policy! See https://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
< Location: https://www.blogger.com/
< Content-Type: text/html; charset=UTF-8
< Date: Mon, 02 Apr 2018 03:48:49 GMT
< Expires: Mon, 02 Apr 2018 03:48:49 GMT
< Cache-Control: private, max-age=0
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Server: GSE
< Accept-Ranges: none
< Vary: Accept-Encoding
< Transfer-Encoding: chunked

以這種方式進行迭代,您肯定會到達實際為您的請求服務的端點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM