okhttp和httpclient的学习记录
okhttp3
Okhttp3
我主要使用Json格式
public Response okhttp(String url,String json) throws OOException{
OkHttpClient client = new OkHttpClient.buider()
.connecTimeout(300,TimeUnit.SECONDS)
.readTimeout(300,TimeUnit.SECONDS)
.writeTimeout(300,TimeUnit.SECONDS)
.cookieJar(new CookieJar(){
@Override
// cookie})
.build();
MediaType mediatype= MediaType.parase("application/json;charset=utf-8);
RequestBody body = RequestBody.creat(mediatype,json);
Request request = new Request.Builder()
.addHeader("Content-Language","zh-CN")
.url(url)
.post(body)
.build();
Call call = client.newCall(request);
return call.execute();
}