开发者

cURL: How can I get url of a page I've got redirected to

开发者 https://www.devze.com 2023-01-01 10:39 出处:网络
I have a curl option FOLLOWLOCATION set to 1. If my script is redirected, is there a chance to fi开发者_开发知识库nd out where have it been redirected to?

I have a curl option FOLLOWLOCATION set to 1. If my script is redirected, is there a chance to fi开发者_开发知识库nd out where have it been redirected to?

Thanks in advance


$ curl -D /dev/stdout -o /dev/null --silent [URL] |grep '^Location:'

Recurse for each value of Location as needed until it is not set in the headers.


I think that if you set the FOLLOWLOCATION to 1, it automatically redirects as many times as you need, and you don't get to know the final destination.

But if you want to know for sure, you'll probably need to follow location manually, check for the 'Location' header each round and repeat the request if need be.


See curl_easy_getinfo() and the CURLINFO_EFFECTIVE_URL option:

"Pass a pointer to a char pointer to receive the last used effective URL."

0

精彩评论

暂无评论...
验证码 换一张
取 消