Android HTTP PUT Request

后端 未结 2 652
粉色の甜心
粉色の甜心 2021-02-02 01:14

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

2条回答
  •  南方客
    南方客 (楼主)
    2021-02-02 02:16

    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
      }
    });
    

提交回复
热议问题