简体   繁体   English

使用Java从Android向Web服务器发送和接收数据(POST和GET)的最佳方式?

[英]Best way to send and receive data(POST and GET) from Android to web server using Java?

In my Android Studio project I am using Java and I have Room database combined with LiveData and ViewModel.在我的 Android Studio 项目中,我使用 Java,并且将 Room 数据库与 LiveData 和 ViewModel 结合使用。

I want to upload some of the tables from Room database(make post requests to a PHP script) and also be able to download( GET request from web server ).我想从 Room 数据库上传一些表(向 PHP 脚本发出发布请求)并且还能够下载(来自 Web 服务器的 GET 请求)。

My question is what is the best approach for this?我的问题是最好的方法是什么? Is a good idea to use Android Studio AsyncTask or should I use RxJava for network calls in order to prevent blocking UI?使用 Android Studio AsyncTask 是个好主意还是应该使用 RxJava 进行网络调用以防止阻塞 UI? I think about using okHttp for send and receiving data.我考虑使用 okHttp 来发送和接收数据。

对于 Android,有一些替代方案可以从您的应用程序发送 HTTP Rest 请求,但最简单和易于配置的是Retrofit ,该库允许从您的 Android 应用程序调用您的 Rest API,您可以附加多个配置以用于日志记录、消息传递等。您可以使用的另一个库是RxJava

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM