B4J Question Help with HttpJob

jroriz

Active Member
Licensed User
Longtime User
I'm having problems with HttpJob.

I'm not sure if the code is correct, but the code below sometimes seems to loop, and the application hangs.

Note that the post is inside a timer. I do not know if this could be a problem.

B4X:
Sub Timer1_tick

    If txtToken.Text = "" Then Return
    
    Timer1.Enabled = False
    
    Dim j As HttpJob
    j.Initialize("j", Me)
    j.PostString("https://pos.globalfoodsoft.com/pos/order/pop", "")
    j.GetRequest.SetHeader("Authorization", decrypt(txtToken.Text))
    j.GetRequest.SetHeader("Accept", "application/json")
    j.GetRequest.SetHeader("Glf-Api-Version", "2")
    j.GetRequest.SetContentType("application/json")

    Wait For (j) JobDone(j As HttpJob)

    If j.Success Then
        Log("success")
        Write(j.GetString)    ' do stuffs
    Else
        Log("error: " & j.ErrorMessage)
    End If
        
    j.Release
    Timer1.Enabled = True
End Sub

Sub JobDone(job As HttpJob)
 
    Log(job.Tag)
    If job.Success Then
        Log(job.JobName & " - " & job.GetString)
    End If

End Sub
 

OliverA

Expert
Licensed User
Longtime User
You do not need a separate JobDone method/sub since you are using Wait For. For how fast is your timer set for?
 
Upvote 0

jroriz

Active Member
Licensed User
Longtime User
You do not need a separate JobDone method/sub since you are using Wait For. For how fast is your timer set for?
Thanks for the help.

My timer is set to 1 minute.

And what is the BEST way to use a call like that, wich includes GetRequest.SetHeader?
 
Upvote 0
Top