Android Question [SOLVED] Trouble downloading web page with HttpUtils2

enemotrop

Member
Licensed User
Longtime User
Hi all,

I'm trying to download and parse this URL using HttpUtils2:

http://www.cofib.es/es/llistat_guardies.aspx?z=Palma&data=26/11/2013

The app downloads many oher URLs using arguments without error. Some using GET commands (with the .Download or .Download2 methods); others using POST commands (with the .PostString or .PostBytes methods), and even some with specific headers.

In this case, if I download the URL above using wget command in Linux, the web downloads perfectly. As wget is very simple and sends no hidden data, cookies or any headers to the web server, I assume that, in this case, a simple GET using the URL above should be enough to obtain the data. The fact is it doesn't. With B4A, no matter which download method I follow, the result is always a 404 error.

Maybe the problem comes with the backslashes of the URL, at the end, in the 'data' parameter. I've tried to escape them using %2f, and passing Chr(47), with no success.

Any ideas?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

enemotrop

Member
Licensed User
Longtime User
Manually called the website selects 26.11.2013 with your url. With http://www.cofib.es/es/llistat_guardies.aspx?z=Palma&data=27.11.2013 it selects the 27th

So using dots in date should work

It doesn't work.

The link is supposed to get a webpage which contains the word 'tblLlistatGuardies'. If not, the returning string contains a label near the end titled 'Error'; it says that 'llistat_guardies.aspx is unreachable in the Castillian part' (at least in my case). Obviously it's an error.

If I enter manually that URI on a browser, or if I download it using wget command (Linux), it downloads the correct URI. But none of the HttpUtils2 methods available doesn't work by now.

The command wget in Linux is as simple as (and it works):

B4X:
wget -O - http://www.cofib.es/es/llistat_guardies.aspx?z=Palma&data=27.11.2013

No headers, no cookies, no other special or hidden parameters

I attach a test project that checks if the string returned after the GET or POST is correct, and displays a msgbox. In my case, in all methods the response is an error.
 
Last edited by a moderator:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use File - Export as zip when uploading projects.

No headers, no cookies, no other special or hidden parameters
Are you sure? You should check it with a tool such as Fiddler.

This code works:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim j As HttpJob
   j.Initialize("j", Me)
   j.Download("http://www.cofib.es/es/llistat_guardies.aspx?z=Palma&data=26/11/2013")
   j.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0")
   j.GetRequest.SetHeader("Accept", "text/html")
End Sub

Sub JobDone(J As HttpJob)
   If J.Success Then
     Log(J.GetString.Contains("tblLlistatGuardies"))
   End If
   J.Release
End Sub
 
Upvote 0

enemotrop

Member
Licensed User
Longtime User
Please use File - Export as zip when uploading projects.


Are you sure? You should check it with a tool such as Fiddler.

This code works:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim j As HttpJob
   j.Initialize("j", Me)
   j.Download("http://www.cofib.es/es/llistat_guardies.aspx?z=Palma&data=26/11/2013")
   j.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0")
   j.GetRequest.SetHeader("Accept", "text/html")
End Sub

Sub JobDone(J As HttpJob)
   If J.Success Then
     Log(J.GetString.Contains("tblLlistatGuardies"))
   End If
   J.Release
End Sub

Thank you very much Erel! It worked. I assumed that the headers weren't necessary, because wget is pretty much simple and it worked smoothly, but I'm afraid it was too much assumption... SOLVED
 
Upvote 0
Top