Android Question retrieve PostString post data into JobDone

Paolo Trevisiol

Member
Licensed User
Hi everyone,

I used:

B4X:
Dim myURL As String = "http://www.mysite.com"
Din szUsr As String = "myself"
Din szPwd As String = "password"
  
Dim j As HttpJob
j.Initialize("MyJob",Me)
Dim generator As JSONGenerator
generator.Initialize(CreateMap("Usr": szUsr, "Pwd": szPwd))
j.PostString(myURL, generator.ToString)

Could I retrieve "myself" and "password" into sub JobDone if Job.Success = FALSE?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
1. Please use [CODE]code here...[/CODE] tags when posting code.
2. You can use the Tag from the Job.
B4X:
Dim j As HttpJob
j.Initialize("MyJob",Me)
dim m as map = CreateMap("User":"myself","Password":"password")
j.Tag = m

In Jobdone you read the Map back.
B4X:
dim m as map = job.Tag
 
Upvote 0

Paolo Trevisiol

Member
Licensed User
B4X:
Sub JobDone(Job As HttpJob)
    Dim bRel As Boolean = True
   
    If ( Job.JobName == "MyJob" ) Then
        bRel = False ' managed by Wait For
    Else
        ' ... managing others jobs ...
    End If
   
    If ( bRel ) Then
        Job.Release
    End If
End Sub

Good code?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
No. Using wait for you do not need the sub at all.
The code should be in the sub where you are using the wait for.
B4X:
   If ( bRel ) Then
        Job.Release
    End If
End Sub
The job must be ALWAYS released.

B4X:
Dim myURL As String = "http://www.mysite.com"
Din szUsr As String = "myself"
Din szPwd As String = "password"
 
Dim j As HttpJob
j.Initialize("MyJob",Me)
dim m as map = CreateMap("Usr": szUsr, "Pwd": szPwd)
Dim generator As JSONGenerator
generator.Initialize(m)
j.PostString(myURL, generator.ToString)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
   Log(j.GetString)
else
    log("User used: "&szUsr)
    log("PW used: "&szPwd)
    log(j.errormessage)
End If
j.Release
 
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
hi, i have tray many ways to postString to and Php script. but no luck.

i try with soapUI and this is the string generate.

IMEI=f269ad6583b84f7a0&bateria=10&longi=18.449928&lat=-69.975105&altitud=25&orientacion='N'

anyone can share with me.

thanks.

php code
B4X:
if (isset($_POST["IMEI"])) {
        $IMEI= $_POST["IMEI"];
        $bateria= $_POST["bateria"];
        $fecha= date("d/m/y H:i:s");
        $longi= $_POST["longi"];
        $lat= $_POST["lat"];
        $altitud= $_POST["altitud"];
        $orientacion= $_POST["orientacion"];

B4a code1
B4X:
    Dim m As String  = ""
    Dim j As HttpJob
    Log(m)
    j.Initialize("", Me)
    j.PostString("http://gpstracker.nowyouseeme.net/appmovil/index.php"&$"?IMEI=${public_data.imei}&bateria=10&longi=${public_data.longitude}&lat=${public_data.lattitude}&altitud=${public_data.altitud}&orientacion=N"$ ,m)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    End If
    j.Release

B4a code 2
B4X:
    Dim m As String  = $"?IMEI=${public_data.imei}&bateria=10&longi=${public_data.longitude}&lat=${public_data.lattitude}&altitud=${public_data.altitud}&orientacion=N"$ 
    Dim j As HttpJob
    Log(m)
    j.Initialize("", Me)
    j.PostString("http://gpstracker.nowyouseeme.net/appmovil/index.php",m)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    End If
    j.Release
 
Upvote 0
Top