Android Question HttpUtils2 version 2.01

mariolu

Member
Licensed User
Longtime User
Hi am trying to get the value of the text string after a php code has been executed.

What is the proper code to evaluate the string contents using getstring


job3.Initialize("Job3", Me)
stringvalue = job3.getstring("http://www.mywebsite.com/stringcode.php")

Not sure if I am phrasing this right, I need a example of how to use the GetString function in HttpUtils2
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim php As HttpJob
    php.Initialize("phptest",Me)
    php.Download("http://www.mywebsite.com/stringcode.php")
End Sub

Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
        Dim res As String
        res = Job.GetString
        Log("JobName: "&Job.JobName&"/Resp:" & res)
        If Job.JobName = "phptest" Then
            Log("Response: "&res)
        Else If Job.JobName = "Init" Then
          Log("")
        End If
    Else
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
 
Upvote 0

mariolu

Member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim php As HttpJob
    php.Initialize("phptest",Me)
    php.Download("http://www.mywebsite.com/stringcode.php")
End Sub

Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
        Dim res As String
        res = Job.GetString
        Log("JobName: "&Job.JobName&"/Resp:" & res)
        If Job.JobName = "phptest" Then
            Log("Response: "&res)
        Else If Job.JobName = "Init" Then
          Log("")
        End If
    Else
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
 
Upvote 0

mariolu

Member
Licensed User
Longtime User
DonManfred, thanks very much for leading me in the right direction. Its exactly what I was looking for.
 
Upvote 0

mariolu

Member
Licensed User
Longtime User

I have a further question. After this piece of code..

1. Dim php As HttpJob
2. php.Initialize("phptest",Me)
3. php.Download("http://www.mywebsite.com/stringcode.php")
(I have other code below here, need to evaluate the string below before executing the rest of the code)
4.xxxxxxxxxxxxxxxxxxxxxx
5.xxxxxxxxxxxxxxxxxxxxxx



I have to get the values of this string to execute further code, problem is that the code continues to execute without
waiting for the code (php.Download) to finish with the evaluated string value.

Not sure how get the results before performing the rest of the code.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub JobDone(Job As HttpJob)
  If Job.Success Then
    Dim res AsString
     res = Job.GetStringLog("JobName: "&Job.JobName&"/Resp:" & res)
     If Job.JobName = "phptest" Then
       Log("Response: "&res)
        4.xxxxxxxxxxxxxxxxxxxxxx
        5.xxxxxxxxxxxxxxxxxxxxxx
     Else If Job.JobName = "Init" Then
       Log("")
    End If
  Else
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub

or

B4X:
Sub JobDone(Job As HttpJob)
  If Job.Success Then
    Dim res AsString
     res = Job.GetStringLog("JobName: "&Job.JobName&"/Resp:" & res)
     If Job.JobName = "phptest" Then
       Log("Response: "&res)
       Dofourandfive
     Else If Job.JobName = "Init" Then
       Log("")
    End If
  Else
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub Dofourandfive
  4.xxxxxxxxxxxxxxxxxxxxxx
  5.xxxxxxxxxxxxxxxxxxxxxx
end sub
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
If you need to do work after the job has completed, then you need to do that work, or call a sub to do it, from the JobDone sub. So your code stops at line 3, and somewhere in JobDone, you say something like

B4X:
If Job.Success AND Job.JobName = "phptest" Then
  ' handle the results here eg
  Dim results As String
  results = Job.GetString
  ' process results as per your lines 4 & 5
End If
 
Upvote 0
Top