V Forum

[ log in ]

How to Get Destination URL After Redirect?

madranet Feb 11 12:21
I'm currently trying to port one of my Python scripts which downloads the latest crossword from a newspaper site. Online the crossword is accessed via a URL like: "http://site.com/crossword/latest/" which automatically redirects to the URL of the latest crossword, a URL like: "http://site.com/crossword/42

So far I've got:

response := http.get("http://site.com/crossword/latest/") or {panic('ERR')}
println("DEBUG: response status => $response.status_code")
println("DEBUG: response headers => $response.headers")
println("DEBUG: response text => $response.

but neither is giving me any output at all:

DEBUG: response status => 0
DEBUG: response headers => {}
DEBUG: response text =>

The connection seems to be being made OK as I don't get any error [and it works fine with other non-directing URLs]. I would have expec
madranet Feb 11 12:24
Hmmm... seem to have had half my post amputated there. here's the rest:

...I would have expected to at least get a `301: moved permanently` status_code response. Anyone got any pointers as to how I can return the resulting URL after the redirection, or otherwise handle a URL which redirects?

Incidentally, I initially had a similar problem when writing
the original Python version. But there I was able to use:


..to return the URL I eventually get redirected to. Not sure how [or if] that could be translated into what's currently available in V.

Powered by Vorum, open-source blogging/forum software written in V