HTTp request(Get rss feed returns Object Moved to error page)

OS: Windows
Haxe version: 4.0.0-rc.1
Hashlink: 1.9

So I am trying to request data from a website but the returned data is erroneous and I can’t replicate the same situation on apitester.com or with other tools(browser/curl).

Here is the code:

var request:haxe.Http;
request = new haxe.Http("http://www.parl.ca/LegisInfo/Home.aspx?ParliamentSession=42-1&Language=E&download=xml")
request.onData = updateDB;
request.onError = error;
request.onStatus = status;

In the function status I get status 302 which is Found but the data I get is a redirect to an error page i.e.:

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2fLegisInfo%2fhttp-500.error%3faspxerrorpath%3d%2fLegisInfo%2fHome.aspx">here</a>.</h2>
</body></html>

When I use the browser it downloads the file and when using curl I can get the xml data. I tried connecting directly with a socket and then doing a customrequest to no avail.

Does this work on another target?

A frequent issue I see when using scripting to access url is user agent filtering,
try changing the User-Agent header to the one of firefox or chrome, could help.

1 Like

I am not sure haxe.Http should handle redirects. If your webserver tells you that the princess is in another castle then there might be cases where you would want to know that you are being redirected.

Curl and browsers just follow redirects automatically, but they do so but starting a second (or third, etc.) http request using the URL given by a 301 / 302 response.

haxe.Http could theoretically have a followRedirects property, but then it would have to deal with redirect loops or neverending redirects.

So I guess you will have to handle redirects in your code.

2 Likes

Changing the User-Agent to the header of firefox worked. Thank you for the response was really helpfull !