Android Question httpjob getString method

Wave

Member
Licensed User
Longtime User
-------

Dim infoMessage As HttpJob
infoMessage.Initialize("infoMessage", Me)
infoMessage.Download2(Main.httpStr & "message.php", Array As String("id", s))

---------

Sub JobDone(Job As HttpJob)
If Job.Success = True Then

Select Job.JobName
Case "infoMessage"
Dim s As String = Job.GetString
If s = "1" Then <-- not working, return 1
ToastMessageShow("this code block", False)
Else If s = "2" Then <-- not working, return 2
ToastMessageShow("this 2.code block", False)
End If
End Select
Job.Release
End If

Can not read the string data.

please help me.
 

DonManfred

Expert
Licensed User
Longtime User
1. Use code tags when posting code
2. what is the result of
B4X:
log(Job.GetString)

try
B4X:
Sub JobDone(Job As HttpJob)
  If Job.Success = True Then
    log(Job.jobname)
    log(Job.GetString)

Select Job.JobName
Case "infoMessage"
Dim s As String = Job.GetString
If s = "1" Then <-- not working, return 1
ToastMessageShow("this code block", False)
Else If s = "2" Then <-- not working, return 2
ToastMessageShow("this 2.code block", False)
End If
End Select
Job.Release
End If
What is the output of the log-commands?
 
Upvote 0

Wave

Member
Licensed User
Longtime User
infoMessage
1
1
PackageAdded: package:b4a.example
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
infoMessage
1
1
infoMessage
1
1
 
Upvote 0

Wave

Member
Licensed User
Longtime User
but

if s = "1" then <-- not working block

Is that character sets may be different ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub JobDone(Job As HttpJob)
  If Job.Success = True Then
      Log(Job.jobname)
      Log(Job.GetString)
        If Job.JobName = "infoMessage" Then
            Dim s As String = Job.GetString
            If s = "1" Then
                ToastMessageShow("this code block", False)
            Else If s = "2" Then
                ToastMessageShow("this 2.code block", False)
            End If
        End If
    End If
    Job.Release
End If
 
Upvote 0

Wave

Member
Licensed User
Longtime User
<?php
/**
* Created by PhpStorm.
* Date: 04/09/2016
* Time: 10:17
*/

echo("1");
?>
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The source of http://basic4android.de/wave.php is the same as you posted.

It is working for me

B4X:
Sub Globals

Private Button1 As Button
Dim Httputils2Label As Label

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
    Dim Job As HttpJob
    Job.Initialize("job", Me)
    Job.download("http://basic4android.de/wave.php")
   
End Sub

Sub JobDone (job As HttpJob)
   
    ProgressDialogHide       
    If job.Success Then
        Log("JobDone("&job.JobName&")")
        Dim res As String = job.GetString
        Log("Response from server: ->"&res&"<-")
        Httputils2Label.Text = res
       
        If res = "1" Then
            ToastMessageShow("Result = 1 ...", True)       
        End If
    Else
        ToastMessageShow("I am Sorry, An Error has Occurred. Please Try Again Later", True)
        Log("ERROR:"&job.ErrorMessage)           
    End If
    job.Release
End Sub
 

Attachments

  • wave.zip
    7.7 KB · Views: 199
Upvote 0

Wave

Member
Licensed User
Longtime User
Thanks for be interested. problem php file (UTF 8 with BOM) encoded. file is encoded as UTF 8, no problem.
 
Upvote 0
Top