Page 1 of 1

get-url with redirection?

Posted: Sat Dec 12, 2009 12:23 am
by zxcel
I want to download the file, but get-url can't do it. That's because the url that i have, redirects me to another url. All browsers, Opera, wget - all of them understand that redirection. How can I do it?

Re: get-url with redirection?

Posted: Sat Dec 12, 2009 9:10 am
by hilti
Try to use CURL instead

Code: Select all

(exec (string "curl -u "http://www.google.com" --progress-bar"))
CURL handles HTTPS, too.

Cheers
Hilti

Re: get-url with redirection?

Posted: Sat Dec 12, 2009 9:12 am
by hilti
Sorry.

That's the correct snippet:

Code: Select all

(exec (string "curl 'http://www.google.com' --progress-bar"))

Re: get-url with redirection?

Posted: Sun Mar 07, 2010 7:00 pm
by Fritz
You can also look into the text "get-url" returns to you. I believe, inside you will find a correct address of the file.

First get-url:

Code: Select all

(get-url "http://lenta.ru/info")
Result:

Code: Select all

"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>302 Found</title>\n</head><body>\n<h1>Found</h1>\n<p>The document has moved <a href=\"http://lenta.ru/info/\">here</a>.</p>\n<hr>\n<address>Apache Server at lenta.ru Port 80</address>\n</body></html>\n"
Parsing correct address:

Code: Select all

(first (regex {(?<=href=")[^"]+} (get-url "http://lenta.ru/info")))
Result:

Code: Select all

"http://lenta.ru/info/"
Final get-url:

Code: Select all

(get-url (first (regex {(?<=href=")[^"]+} (get-url "http://lenta.ru/info"))))

Re: get-url with redirection?

Posted: Mon Mar 08, 2010 3:08 pm
by Lutz
In the past 'get-url' only handled re- "Location:" headers together with error codes 301 and 303. I have now added error code 302 for v.10.2.0 to force a second request also on this error code, and it handles the http://lenta.ru/info case correctly.