问题描述
我开始使用 b4a,我想发送带有有效负载(数据)的 post 请求。 在 python 中它是这样工作的:
requests.post(url,data)
解决方法
在您的项目中参考 OkHttpUtils2。 并发布如下数据:
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
,
作为 G.P. 答案的扩展,如果您想在同一个子程序中等待作业完成而不是创建新子程序,您可以使用 Wait For
。像这样:
'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