Android Tutorial HttpUtils2 - Web services are now even simpler

walterf25

Expert
Licensed User
Longtime User
HTTP multiple requests

Hi Erel, i'm updating one of my apps and i need to figure out a way to make multiple HTTP requests one after the other, there's sometimes where I will need to make up to 16 requests, i tried to do this last night but i keep getting the "main page could not load" error.
I got it to work if i set a timer and assign each request to run inside a timer but this takes way too long, so i need to figure out a way to make those requests faster.
A little background about my app.
I have a database which has around 20,000 records in it, at first i use the GPS library to locate the user's current location and then i look at the database and see if the user's location is within a few meters from any of the coordinates in the database once it finds a close location then i send an HTTP request, this is for a Local Transportation bus schedule app that i made, this update is so that when the user opens the app it automatically detects his/her location and gives him a schedule of the bus stops near him/her, as you can imagine, if there's around 10 bus stops near by there will be 10 http requests.
So how can i handle this?

Thanks Erel!
 

Smee

Well-Known Member
Licensed User
Longtime User
I have a small problem trying to remove items from a list.
The code is as follows

B4X:
Sub JobDone (Job As HttpJob)
If Job.Success = True Then
Select Job.JobName

Case "Job3"
DownloadFiles(Job.GetString)
..
..
   Job.Release
End Sub

Sub DownloadFiles (st As String)
'Dim ListFiles As List
ListFiles = s.Split(st,Chr(13)&Chr(10))
...
..
..
..

ListJpegs.RemoveAt(1)
End Sub

When the program hits the Remove at line i get the error
java.lang.UnsupportedOperationException

Can you tell me what is wrong with this line or how i can remove certain items?

Many thanks for the great code
 

Smee

Well-Known Member
Licensed User
Longtime User
String.Split returns a read-only list. You should use this code:
B4X:
ListFiles.AddAll(s.Split(...))

Note that the first index is 0 not 1.

Many thanks Erel,
yeah i know about the first index, it was just an example, i may need to remove at random locations. and i know i have to remove from the top first. many thanks again.
 

AllanD

Member
Licensed User
Longtime User
getting Already working. Request ignored when using httputils2

Hello,
I am getting an error when using the httputils. The log says Already "working. Request ignored" when attempting to run a job.

It is a possing sort of activity so a connection to the servis made a few times and then stop working.

Is httputils2 the latest library, has it been replaced?

What can I do?
 

AllanD

Member
Licensed User
Longtime User
getting Already working. Request ignored when using httputils2

I am sorry folks, I was using the old version and not httputils2. After upgrading all is well:sign0060:
 

tutecnicodavid

Member
Licensed User
Longtime User
httupultis 2 problem

My problem is that if I throw several postString not seem to follow the order of execution, ie it can end up in different order or even not finishing started ... it can not be synchronized to work with the order in which they call?

My code is something like this:

1.- C1.PostString("http://" & Main.IPServidor & "/mabe/guardar_control_entrada.php?numero_partida=" & NumeroPartida & "&observaciones=" & s.EncodeUrl(txtObservaciones.Text,"UTF8") & "&id_usuario=" & s.EncodeUrl(Main.CodigoUsuario,"UTF8"),"")

2.- C2.postString("http://"& Main.IPServidor &"/mabe/actualizar_control_entrada.php?id_control_entrada=" & txtNumeroControl.Text & "&numero_partida=" & NumeroPartida & "&observaciones=" & s.EncodeUrl(txtObservaciones.Text,"UTF8"),"")

3.- For i=0 To TotalMedidasBrix-1
If ListaMedidaBrix(i).Text<>0 AND ListaMedidaBrix(i).Text<>"" Then
C(i).Initialize("insertarmedidascontrolentrada",Me) C(i).PostString("http://"& Main.IPServidor & "/mabe/insertar_medida_control_entrada.php?id_control_entrada=" & txtNumeroControl.Text & "&medida_brix=" & s.EncodeUrl(ListaMedidaBrix(i).Text,"UTF8"),"")
End If
Next

but instead of ending 1, 2 and 3 ... I think that overlap and chace give an error and does not generate the records in the database whenever.

Please say Aguien know help me: Sign0085:
 

stevel05

Expert
Licensed User
Longtime User
Have you tried using the JobDone callback and starting the next job when the previous one has finished?
 

tutecnicodavid

Member
Licensed User
Longtime User
jobdone callback

I do not understand what you mean with "JobDone callback" ... could you give me an example? Thanks and sorry my ignorance: Confundido:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Http requests are executed asynchronously. So if you submit several jobs the completion order is not deterministic. You can use Job.JobName to find out which Job has just completed (in JobDone). If you really need to send the next job only after the previous one has completed then you should submit the next job from JobDone.
 

javiers

Active Member
Licensed User
Longtime User
Error with HttpJob...

Hello
I use the following code to get an image and then save it.

Dim job As HttpJob
job.Initialize ("000", Me)
job.Download ("https://www.fnmoc.navy.mil/wxmap_cgi/dynamic/NVG/current/nvg10.tas.000.europe2.png")

I get the following error:

Error: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

Any solutions?

Thanks
 

javiers

Active Member
Licensed User
Longtime User
Thanks. Solved.

Thanks Erel.
work properly with your answer.:icon_clap:

A greeting
 

NFOBoy

Active Member
Licensed User
Longtime User
So, I am using HTTPUtils2, and it works great, even easier than I expected, as it took me two hours to realize how easy it was to get a bmp downloaded from a link. (I was trying to figure out how to tell the the job it was a bmp so it could be put into an imageview, vs a page of text, but that's done auto-magically!)

In fact, that's my question, How is that done? I have looked through the Httpjob and HttpUtils2 code, and can follow what is happening in there. (at least I think I do) The Service runs an asynchronous request when the HTTPClient says it was successful, and saves the data to the TempFolder (whatever was retrieved), which is then assigned to the instantiated job. But I'm not seeing how the job knows what it was? Is that all based on the page that was requested?

If this is something basic I should understand, can you point me to where I can read up on it?

Ross
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…