直接在URL后自动添加请求的参数
public static ApiRequest newGet(String url, HashMap<String, Object> params) {
//创建url的builder类,用来构建复杂的url
HttpUrl.Builder urlBuilder = HttpUrl.get(url).newBuilder();
urlBuilder.addQueryParameter("token", SharedPreferencesUtil.get("token"));
for (Map.Entry<String, Object> entry : params.entrySet()) {
//添加查询的参数
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue().toString());
}
Request request = new Request.Builder()
.url(urlBuilder.build())
.get()
.build();
return new ApiRequest(request);
}