[英]How to send Json PUT request from Android to rails server
The following is the ajax code used by the website to change the two feilds ability_bpm and endurance_bpm 以下是网站用来更改两个字段的ajax代码:skill_bpm和endurance_bpm
function editBatch_Ajax(id, batch_data){
$.ajax({
url: '/batches/'+ id,
type: 'put',
context: 'this',
dataType: 'json',
data: {
batch: batch_data,
id: id
},
success: function(msg){
$('#' + id + ' .' + Object.keys(batch_data)[0]).text(batch_data[Object.keys(batch_data)[0]]);
},
error: function(jqXHR, textStatus, errorThrown) {}
});
}
sends a PUT request from a Ajax call. 通过Ajax调用发送PUT请求。 Now I want to do the same thing from an android application. 现在,我想从android应用程序执行相同的操作。 here 这里
data: {
batch: batch_data,
id: id
},
will be something like 会像
data : {
batch: {
ability_bpm: 40
},
id: 0
}
The website that I webserver is running at http://www.rudimentor.me/ 我的网络服务器正在运行的网站http://www.rudimentor.me/
I am a beginer to android. 我是android的初学者。 So far I have gotten to display the data available at the server in a listview I need to have this to change the values on the server. 到目前为止,我已经在列表视图中显示了服务器上可用的数据,我需要使用它来更改服务器上的值。 I have also tried to send request from a rest client in a browser but cannot figure it out 我也尝试过在浏览器中从其他客户端发送请求,但无法弄清楚
You can use this library to make your HTTP Calls: 您可以使用此库进行HTTP调用:
http://loopj.com/android-async-http/ http://loopj.com/android-async-http/
Here you can find some example how to use this library: 在这里,您可以找到一些如何使用此库的示例:
https://github.com/franzejr/android-boilerplate/blob/master/app/src/main/java/controllers/SampleController.java https://github.com/franzejr/android-boilerplate/blob/master/app/src/main/java/controllers/SampleController.java
And also you can use the GSON to help you handling JSONs. 而且,您还可以使用GSON帮助您处理JSON。 It's pretty straightforward. 这很简单。
I would say there are a number of options. 我会说有很多选择。 I prefer Retrofit . 我更喜欢翻新 。
Here is a link to a question with some good comparisons of the various options. 这是一个问题的链接,其中对各种选项进行了很好的比较。
Comparison of Android networking libraries: OkHTTP, Retrofit, and Volley Android网络库的比较:OkHTTP,Retrofit和Volley
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.