简体   繁体   中英

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

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. Now I want to do the same thing from an android application. 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/

I am a beginer to 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://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

And also you can use the GSON to help you handling JSONs. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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