use of com.springboot.sample.util.okhttp.HttpException in project spring-boot-examples by tedburner.
the class OkHttpServiceImpl method GET.
@Override
public byte[] GET(String baseUrl, Map<String, String> queryParams) throws IOException {
// 拼装param
HttpUrl.Builder urlBuilder = HttpUrl.parse(baseUrl).newBuilder();
for (Map.Entry<String, String> item : queryParams.entrySet()) {
urlBuilder.addQueryParameter(item.getKey(), item.getValue());
}
HttpUrl httpUrl = urlBuilder.build();
// 发送请求
Request request = new Request.Builder().url(httpUrl.toString()).get().build();
Response response = ReqExecute(request);
if (!response.isSuccessful()) {
throw new HttpException(response, "exception code:" + response.code());
}
return response.body().bytes();
}
use of com.springboot.sample.util.okhttp.HttpException in project spring-boot-examples by tedburner.
the class OkHttpServiceImpl method POST.
@Override
public byte[] POST(String url, String jsonBody) throws HttpException, IOException {
RequestBody body = RequestBody.create(MEDIA_JSON, jsonBody);
Request request = new Request.Builder().url(url).post(body).build();
Response response = ReqExecute(request);
if (!response.isSuccessful()) {
throw new HttpException(response, "exception code:" + response.code());
}
return response.body().bytes();
}
Aggregations