网友通过本文主要向大家介绍了okhttp使用,android okhttp使用,okhttp3.0使用,okhttp使用方法,okhttp使用详解等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
OKHttp,okhttp使用
一.原生OKHttp的Get和Post请求
1.OKHttp_GET 请求
private String get(String url) throws IOException { Request request = new Request.Builder() .url(url) .build(); Response response = client.newCall(request).execute(); return response.body().string(); }
2.OKHttp_POST 请求
private 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(); }
二.第三方封装好的OKHttp库-okhttp-utils