简体   繁体   English

如何将Json PUT请求从Android发送到Rails服务器

[英]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.

相关问题 通过Android中的HTTP put请求将JSON发送到服务器 - send JSON to server via HTTP put request in android Android:如何将数据从服务器发送到android而没有来自android的请求? - Android:How to send data from server to android with no request from the android? 从Android发送JSON请求 - Send JSON request from Android 如何在不发送JSON请求的情况下从服务器获取JSON - How to get JSON from server without send JSON request 如何将JSon作为BODY发送到Android应用程序的服务器POST请求中? - How do I send JSon as BODY In a POST request to server from an Android application? 如何发送创建一个JSON字符串并将其从服务器发送到android? - How to send create a JSON string and send it from server to android? Android:Rest PUT-如何在服务器上发送数据 - Android: Rest PUT - how send data on server 如何从Android中的单个选项卡发送服务器请求? - How to send Server request from single tab in android? 如何从Android上的RestSharp向WebAPI服务器发送POST请求 - How to send a POST request from RestSharp on android to a WebAPI server 如何从android studio向服务器发送删除请求? - How to send delete request to the server from android studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM