OkHttp in android for making network requests

前端 未结 8 1576
北海茫月
北海茫月 2020-12-29 08:18

What I am trying to do::

I am trying to learn the usage of Okhttp for making networking calls in android


What I have done

8条回答
  •  时光说笑
    2020-12-29 09:02

    I think you should use the new 2.0 RC of okHttp.

    To make a POST petition, the best is :

    String post(String url, String json) throws IOException {
        RequestBody body = RequestBody.create(JSON, json);
        Request request = new Request.Builder()
            .url(url)
            .post(body)
            .build();
        Response response = client.newCall(request).execute();
        return response.body().string();
    }
    

提交回复
热议问题