Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://www.google.com")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
End If
j.Release
Same code runs without any problem within B4XPages but itdoesn't using Console (Non-UI).
Resumable subs can only work when there is a message queue. By default, server handlers end when the Handle sub is completed. They do not create a message loop. If you want to wait for an event then you need to call StartMessageLoop and later StopMessageLoop. Example of handler that downloads...
Sub AppStart (Args() As String)
Dim tr As TextReader
tr.Initialize(File.OpenInput(File.DirApp, Args(0)))
Dim line As String
line = tr.ReadLine
Do While line <> Null
line = tr.ReadLine
Dim j As HttpJob
j.Initialize("j", Me)
j.Download(line)
Log("Downloading: " & line)
StartMessageLoop
Loop
tr.Close
ExitApplication2(0)
End Sub
B4X:
Sub JobDone(Job As HttpJob)
If Job.Success Then
Log(Job.GetString)
Log("ENDDDDDDDDDDDD")
'...
Else
Log(Job.ErrorMessage)
End If
Job.Release
StopMessageLoop
End Sub
But I get an error just before download second file:
Ha ocurrido un error en la línea: 177 (HttpJob)
java.lang.NullPointerException: url == null
at okhttp3.Request$Builder.url(Request.java:132)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest.InitializeGet(OkHttpClientWrapper.java:392)
at b4j.example.httpjob._download(httpjob.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.main(main.java:29)
Sub AppStart (Args() As String)
Download
StartMessageLoop
End Sub
Sub Download
Dim lines As List = File.ReadList(...)
For Each line As String In lines
Dim j As HttpJob
j.Initialize("", Me)
j.Download(line)
Wait For (j) JobDone (j As HttpJob)
If j.Success Then
...
End If
j.Release
Next
ExitApplication