1

i started working with b4a and i want to send post request with payload(data). In python it works like this :

requests.post(url,data)

2 Answers2

2

Reference OkHttpUtils2 in your projects. and post data like:

Sub Activity_Create(FirstTime As Boolean)

   'Send a POST request
   Dim Post As HttpJob   
   Post.Initialize("Job2", Me)
   Post.PostString("http://www.basic4ppc.com/print.php", "key1=value1&key2=value2")

End Sub

Sub JobDone (Job As HttpJob)

    'print the result to the logs
     If Job.Success = True Then Log(Job.GetString)
     Else    Log("Error: " & Job.ErrorMessage)
     Job.Release

End Sub

reference: https://www.b4x.com/android/forum/threads/httputils2-web-services-are-now-even-simpler.18992/#content

Gray Programmerz
  • 479
  • 1
  • 5
  • 22
1

As an extension to G.P.'s answer you can use Wait For if you want to wait for the job to complete in the same sub instead of creating a new sub. Like this:

'Send a POST request
Dim j As HttpJob   
j.Initialize("", Me)
j.PostString(url, data)

'Now that we have sent the request, we wait for it to complete
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
    'This will print the request's response
    Log(j.GetString)
End If
j.Release
Max
  • 160
  • 3
  • 15