首页 > 解决方案 > 如何使用 basic4android 发布有效载荷

问题描述

我开始使用 b4a,我想发送带有有效负载(数据)的发布请求。在 python 中它是这样工作的:

requests.post(url,data)

标签: basic4android

解决方案


在您的项目中引用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


推荐阅读