且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

重定向curl后获取最终URL

更新时间:2023-11-26 16:41:10

curl-w选项,子变量url_effective 寻找.

curl's -w option and the sub variable url_effective is what you are looking for.

类似

curl -Ls -o /dev/null -w %{url_effective} http://google.com

更多信息


-L         Follow redirects
-s         Silent mode. Don't output anything
-o FILE    Write output to <file> instead of stdout
-w FORMAT  What to output after completion

更多

您可能要添加 -I (这是一个大写字母) i),这将使命令不下载任何主体",但是它随后也使用HEAD方法,这不是所包含的问题,并且可能会更改服务器的功能.有时,即使服务器对GET的响应很好,服务器对HEAD的响应也不会很好.

You might want to add -I (that is an uppercase i) as well, which will make the command not download any "body", but it then also uses the HEAD method, which is not what the question included and risk changing what the server does. Sometimes servers don't respond well to HEAD even when they respond fine to GET.