Android Question HTTPUtils2 Issue

rbw152

Member
Licensed User
Longtime User
Hello all,

Using HTTPUtils2 and it's the first time i'm using web services, so please forgive me if I come across ignorant.

I've discovered that my code after calling the Download sub is not holding the response string i'm getting back from the webservice (i.e. the code is being run before the JobDone sub is triggered). I put a DoEvents line after calling the download sub, but then any code after that call is not being run at all (but the JobDone sub is tiggered properly and allocates the response string to the variable, just the way I want it to).

Is there a way to let JobDone get triggered without the code after the DownloadData call being run WITHOUT using DoEvents (as it seems to break everything) :\

Many thanks in advance!
 

rbw152

Member
Licensed User
Longtime User
B4X:
'Activity module
Sub Process_Globals
   Dim webresponse As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim job1, job2, job3 As HttpJob
    job1.Initialize("Job1", Me)
   
    'Send a GET request
    job1.Download2("http://www.b4x.com/print.php", _
        Array As String("first key", "first value :)", "second key", "value 2"))
   
    'Send a POST request
    job2.Initialize("Job2", Me)
    job2.PostString("http://www.b4x.com/print.php", "first key=first value&key2=value2")

    'Send a GET request
    job3.Initialize("Job3", Me)
    job3.Download("http://www.b4x.com/android/forum/data/avatars/m/0/1.jpg?1374051458")
    DoEvents 'Take out = empty webresponse / Leave in = Msgbox below doesn't show
    Msgbox(webresponse,"DEBUG MESSAGE") 'NEED TO ACCESS WEBRESPONSE VARIABLE (JobDone needs to have run)
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "Job1", "Job2"
                'print the result to the logs
                Log(Job.GetString)
                webresponse = Job.GetString 'FILL VARIABLE
            Case "Job3"
                'show the downloaded image
                Activity.SetBackgroundImage(Job.GetBitmap)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

This is the HTTPUtils 2 example with some code added to show the problem. My project code is a little more confusing but the same principle applies in there as it does in the example code posted above.

Thanks!
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I am not sure why the msgbox doesnt show when you remove doevents.

However, this flow is never going to work. You cannot check the webresponse in the same sub.
You have to let the other code in HTTPUtils2 and JoneDone to run first, it will not run if you are hung in some other sub.

You have to put the messagebox inside JobDone to see the response, and call any other subs from there.
 
Upvote 0

rbw152

Member
Licensed User
Longtime User
Thanks for your quick reply. I shall change the flow of how i'm using HTTPUtils2. I appreciate your help ;)
 
Upvote 0
Top