cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: How to derive/capture the 301 url?

From: bruce <badouglas_at_gmail.com>
Date: Mon, 12 Sep 2016 14:50:04 -0400

Hey guys..

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/'

This gets the actual "storeId" in the redirected url. --pretty sure the
sed could be cleaned up!!

On Mon, Sep 12, 2016 at 1:45 PM, Roman Neuhauser <neuhauser+curl_at_sigpipe.cz>
wrote:

> # badouglas_at_gmail.com / 2016-09-12 12:37:38 -0400:
> > Morn.
> >
> > Simple (I hope question)..
> >
> > I can do a basic curl
> > 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 -L "
> > http://case.bncollege.com"
> >
> > and I see the redirected url in the output stream... Short of crafting a
> > bash script/process. Is there an easier way to get the 301/redirected
> url.
> > In this case, the url is
> >
> > < HTTP/1.1 301 Moved Permanently
> > < Location:
> > http://case.bncollege.com/webapp/wcs/stores/servlet/
> BNCBHomePage?storeId=16053&catalogId=10001&langId=-1
> >
> > Is there a way to trigger off the "Location" in the returned headers?
>
> you seem to be looking for the -w option, specifically %{redirect_url}.
>
> --
> roman
> -------------------------------------------------------------------
> 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
>

-------------------------------------------------------------------
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