curl-users
Re: How to derive/capture the 301 url?
Date: Mon, 12 Sep 2016 16:02:40 -0400
On 9/12/2016 2:50 PM, bruce wrote:
> Per my question.. Here's what I came up with in a few mins.. It works,
> getting me the actual data from the Location/redirected 301 url.
>
> If there's a better soln, let me know and I'll check it out.
>
> Thanks
>
> curl -v -A "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
> Firefox/45.0" --cookie-jar aa.lwp --cookie aa.lwp -i
> "http://case.bncollege.com" | egrep -A 10 '301 Moved Permanently|302
> Found' | grep 'Location' | awk -F': ' '{print $2}' | tail -1 | sed
> 's/.*storeId=\(.*\)&catalogId=10001&langId=-1/\1/'
Please try what Roman Neuhauser suggested earlier, use redirect_url
since that is only filled when there's a redirect. Refer to --write-out [1].
location=`curl -w "%{redirect_url}" http://google.com \
-o /dev/null --silent 2>/dev/null`
echo "$location"
[1]: https://curl.haxx.se/docs/manpage.html#-w
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-users
FAQ: https://curl.haxx.se/docs/faq.html
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-09-12