簡體   English   中英

如何使用 basic4android 發布有效載荷

[英]How to post a payload with basic4android

我開始使用 b4a,我想發送帶有有效負載(數據)的發布請求。 在 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

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

作為 GP 答案的擴展,如果您想等待作業在同一個 sub 中完成而不是創建一個新的 sub,則可以使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM