get-url with redirection?
get-url with redirection?
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?
Try to use CURL instead
CURL handles HTTPS, too.
Cheers
Hilti
Code: Select all
(exec (string "curl -u "http://www.google.com" --progress-bar"))
Cheers
Hilti
--()o Dragonfly web framework for newLISP
http://dragonfly.apptruck.de
http://dragonfly.apptruck.de
Re: get-url with redirection?
Sorry.
That's the correct snippet:
That's the correct snippet:
Code: Select all
(exec (string "curl 'http://www.google.com' --progress-bar"))
--()o Dragonfly web framework for newLISP
http://dragonfly.apptruck.de
http://dragonfly.apptruck.de
Re: get-url with redirection?
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:
Result:
Parsing correct address:
Result:
Final get-url:
First get-url:
Code: Select all
(get-url "http://lenta.ru/info")
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"
Code: Select all
(first (regex {(?<=href=")[^"]+} (get-url "http://lenta.ru/info")))
Code: Select all
"http://lenta.ru/info/"
Code: Select all
(get-url (first (regex {(?<=href=")[^"]+} (get-url "http://lenta.ru/info"))))
Re: get-url with redirection?
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.