美文网首页
OKHttp3 get方法 传参及header

OKHttp3 get方法 传参及header

作者: 温一 | 来源:发表于2020-01-13 20:38 被阅读0次

private static final OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();

public static void get(String url, Map<String,String>params, Callback responseCallback) {
HttpUrl.Builder httpBuilder = HttpUrl.parse(url).newBuilder();
if (params != null) {
for(Map.Entry<String, String> param : params.entrySet()) {
httpBuilder.addQueryParameter(param.getKey(),param.getValue());
}
}
Request request = new Request.Builder().url(httpBuilder.build()).build();
client.newCall(request).enqueue(responseCallback);
}

相关文章

网友评论

      本文标题:OKHttp3 get方法 传参及header

      本文链接:https://www.haomeiwen.com/subject/qpvnactx.html