Android HTTP PUT Request

Viewed 26325

Can anyone give me a HTTP PUT request example code for Android?

2 Answers

It's better to use a library like Android Async HTTP or Volley that take the complexity out of networking and make it easier to handle request responses. This is how you would do it with AsyncHTTP:

AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("some_key", "value-1");
params.put("another_key", "value-2");

client.put(url, params, new AsyncHttpResponseHandler {
  public void onSuccess(int statusCode, Header[] headers, String response) {
    // Do something with response
  }
});
Related