B4J Question jOkHttpUtils2 JobDone answer

Toley

Active Member
Licensed User
Longtime User
Hello, I'm using jOkHttpUtils2 to send a PostString request to a custom Server (not coded by me and not in B4J). When I send the Post, I received an answer that I can see in the Logs windows although I'm not logging anything in my code. I want to catch that answer in my code to display it but I don't know how. I'm using Job.GetString to get the result but I only receive [] as an answer. The real answer I need is only shown in my Logs window!

Here is the part of code I use to get and display the message:
B4X:
Sub JobDone (Job1 As HttpJob)
    act_result.Initialize("act_result", 300, 150)
    act_result.RootPane.LoadLayout("ActivResult")
    If Job1.Success = True Then
        lbl_actres.Text = "Activation Success"
        lbl_actmsg.Text = ""
    Else
        lbl_actres.Text = "Activation Failed"
        lbl_actmsg.Text = Job1.GetString
    End If
    act_result.ShowAndWait
End Sub
and here is the returning window:

 

Attachments

  • ActResult.gif
    ActResult.gif
    3.6 KB · Views: 281

Mark Read

Well-Known Member
Licensed User
Longtime User
Have you had a look at Job1.GetInputStream, is there anything there?
 
Upvote 0

Toley

Active Member
Licensed User
Longtime User
Just to add some info, when I use Job.ErrorMessage I get "unknown status" instead of the message in the log window.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Job.GetInputStream will not help here.

The problem is that your server returns an error status.
Use OkHttpUtils2 source code instead of the library and change hc_ResponseError in HttpUtils2Service to:
B4X:
Sub hc_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
   If Response <> Null Then
     Dim job As HttpJob = TaskIdToJob.Get(TaskId)
     job.Tag = Response.ErrorResponse
     Log(Response.ErrorResponse)
     Response.Release
   End If
   CompleteJob(TaskId, False, Reason)
End Sub
The message that you are looking for will be stored in Job.Tag.
 
Upvote 0
Top