如何显示重定向链中的所有 URL?

fel*_*the 49 wget curl

我正在寻找一种方法来显示重定向链中的所有 URL,最好是从 shell。我找到了一种几乎可以用 curl 完成的方法,但它只显示第一个和最后一个 URL。我想看看他们所有人。

必须有一种方法可以简单地做到这一点,但我一生都无法找到它是什么。

编辑:自从提交这个我已经找到了如何使用 Chrome(CTRL+SHIFT+I->网络选项卡)来做到这一点。但是,我仍然想知道如何从 Linux 命令行完成它。

yae*_*shi 69

简单地使用wget怎么样?

$ wget http://picasaweb.google.com 2>&1 | grep Location:
Location: /home [following]
Location: https://www.google.com/accounts/ServiceLogin?hl=en_US&continue=https%3A%2F%2Fpicasaweb.google.com%2Flh%2Flogin%3Fcontinue%3Dhttps%253A%252F%252Fpicasaweb.google.com%252Fhome&service=lh2&ltmpl=gp&passive=true [following]
Location: https://accounts.google.com/ServiceLogin?hl=en_US&continue=https%3A%2F%2Fpicasaweb.google.com%2Flh%2Flogin%3Fcontinue%3Dhttps%3A%2F%2Fpicasaweb.google.com%2Fhome&service=lh2&ltmpl=gp&passive=true [following]
Run Code Online (Sandbox Code Playgroud)

curl -v还显示了一些信息,但看起来不如wget.

$ curl -v -L http://picasaweb.google.com 2>&1 | egrep "^> (Host:|GET)"
> GET / HTTP/1.1
> Host: picasaweb.google.com
> GET /home HTTP/1.1
> Host: picasaweb.google.com
> GET /accounts/ServiceLogin?hl=en_US&continue=https%3A%2F%2Fpicasaweb.google.com%2Flh%2Flogin%3Fcontinue%3Dhttps%253A%252F%252Fpicasaweb.google.com%252Fhome&service=lh2&ltmpl=gp&passive=true HTTP/1.1
> Host: www.google.com
> GET /ServiceLogin?hl=en_US&continue=https%3A%2F%2Fpicasaweb.google.com%2Flh%2Flogin%3Fcontinue%3Dhttps%253A%252F%252Fpicasaweb.google.com%252Fhome&service=lh2&ltmpl=gp&passive=true HTTP/1.1
> Host: accounts.google.com
Run Code Online (Sandbox Code Playgroud)

  • 如果我没记错的话,它只适用于使用位置标头的重定向,不适用于 301 http 代码 (3认同)