[英]How to post a payload with basic4android
i started working with b4a and i want to send post request with payload(data).我开始使用 b4a,我想发送带有有效负载(数据)的发布请求。 In python it works like this:
在 python 中,它的工作方式如下:
requests.post(url,data)
Reference OkHttpUtils2 in your projects.在您的项目中引用OkHttpUtils2 。 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参考: https://www.b4x.com/android/forum/threads/httputils2-web-services-are-now-even-simpler.18992/#content
As an extension to GP'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.作为 GP 答案的扩展,如果您想等待作业在同一个 sub 中完成而不是创建一个新的 sub,则可以使用
Wait For
。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.