cURL: How can I get url of a page I've got 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."
精彩评论