Downloading resources is simpler with the new Resumable Subs feature. Using Wait For we can wait for the JobDone event in the same sub that started the download. No longer is it needed to have a single sub that handles all requests results. Simplest example: Dim j As HttpJob j.Initialize(""...
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://www.cloud.lims.fr/lims/webservices/databases")
j.GetRequest.SetHeader("Authorization","Basic c2dzX2FkbWluOkxTZGJAZG1pbjAw")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
End If
j.Release
2.
B4X:
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://www.cloud.lims.fr/lims/webservices/databases/NUTRILABO-20231106-Monday.backup")
j.GetRequest.SetHeader("Authorization","Basic c2dzX2FkbWluOkxTZGJAZG1pbjAw")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirApp, "filename.dat", False)
File.Copy2(j.GetInputStream, out)
out.Close
End If
j.Release
Here is simple example how use simple call - is api live:
B4X:
Sub IsAPILive As ResumableSub
Dim Ok As Boolean = False
' Url is written in INI file which is readed on start
Dim url As String = Main.InitConfig.Get("http_link") & "hallo"
Dim requestBody As String = "" ' Modify this as per your requirements
Dim lJobs As List
lJobs.Initialize
Dim Job As HttpJob
Job.Initialize("isLive", Me)
Job.PostString(url, requestBody)
Job.GetRequest.SetContentType("application/json")
Job.GetRequest.Timeout = Main.InitConfig.Get("api_timeout")
' Adding header - like DateFrom
Dim headers As Map
headers.Initialize
headers.Put("DateFrom", DateFrom)
For Each headerKey As String In headers.Keys
job.GetRequest.SetHeader(headerKey, headers.Get(headerKey))
Next
DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss"
Dim Datum As String = DateTime.Date(DateTime.Now)
' waiting for answer
Wait For (Job) JobDone(Job As HttpJob)
If Job.Success Then
Dim response As String = Job.GetString
' Log(response) ' Do somet hing with the response
Dim jRead As JSONParser
jRead.Initialize(response)
Dim jRoot As Map = jRead.NextObject
Dim answare As Int = jRoot.Get("a")
Dim success As String = jRoot.Get("s")
' if is ok
If answare = "200" And success = "Ok" Then
Ok = True
End If
Else
Log("Error: " & Job.ErrorMessage)
End If
Job.Release
Return Ok
End Sub