Android Question OkHttpUtils2 - PostString with Download to receive data from the POST


New Member
Hi, it has been a while since I used B4A, and now it seems to be the fastest way to build Proofs of Concept apps super fast and easy!

How can we POST then receive the response payload?

Background: We have many data web and cloud APIs. When we POST a body of JSON data (for a new record in the system), the POST request routinely returns the new record id (like a UUID). It will also return an error and details if the data was wrong or incomplete. We also add headers for APIKEYs and other things.

We can get the PostString to work with the headers, but I don't know how to get the returned UUID/data from the POST request, since I am not using the Download, and the JobDone does not seem to return the data.

We have done much searching on the web, but we cannot find that one piece of code example that does what we need.

Thank you


Licensed User
Longtime User
Upvote 1


New Member
@DonManfred thank you for your quick response. You were right, it does return data.

With your reply, I did some more research in the library documentation and I discovered that there was a change, when I was using a JobDone Sub routine process for all requests (the way it was designed earlier), the response was empty for PostString for me. But when I read that "Wait For JobDone" was supported more recently without having the need for the JobDone Sub Routine, THAT JobDone returned the data.

I am no longer sure if the resolution was the 'Wait for JobDone" or I could have had a mistake in the original JobDone Sub Routine prompting my message, but I no longer have that code.

To close this forum post, I figured I would post the code snippet, it might be helpful to others.

This returns a token to be used for other APIs (URL was obfuscated)
PostString returning data in response:
Dim jobLogin As HttpJob
jobLogin.Initialize("JobLogin", Me)
jobLogin.GetRequest.SetHeader("X-User", strUser)
jobLogin.GetRequest.SetHeader("X-Password", strPass)
jobLogin.GetRequest.SetHeader("Accept", "application/json")
Wait For (jobLogin) JobDone(jobLogin As HttpJob)
If jobLogin.Success = True Then
   If jobLogin.GetString = "{}" Then
      MsgboxAsync("Invalid Username or Password", "Login")
      Wait For MsgBox_Result (Result As Int)
      Dim JSON As JSONParser
      Dim Map1 As Map
      Map1 = JSON.NextObject
      strApiKey = Map1.Get("token")
      ToastMessageShow(strApiKey, True)
   End If
End If
Upvote 0