get-url with redirection?

Started by zxcel, December 11, 2009, 04:23:13 PM

Previous topic - Next topic

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?

hilti

#1
Try to use CURL instead


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

CURL handles HTTPS, too.



Cheers

Hilti
--()o Dragonfly web framework for newLISP

http://dragonfly.apptruck.de\">http://dragonfly.apptruck.de

hilti

#2
Sorry.



That's the correct snippet:


(exec (string "curl 'http://www.google.com' --progress-bar"))
--()o Dragonfly web framework for newLISP

http://dragonfly.apptruck.de\">http://dragonfly.apptruck.de

Fritz

#3
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:
(get-url "http://lenta.ru/info")

Result:
"<!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:
(first (regex {(?<=href=")[^"]+} (get-url "http://lenta.ru/info")))

Result:
"http://lenta.ru/info/"

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

Lutz

#4
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">http://lenta.ru/info case correctly.