POST请求
log.info("调用xxx接口请求连接 :{},请求体:{}", url, JSON.toJSONString(body));
try (
HttpResponse response = HttpRequest.post(url)
.header("Authorization", token)
.body(JSON.toJSONString(body))
.execute();
) {
String responseBody = response.body();
if (response.isOk()) {
log.info("调用xxx接口成功,返回数据:{}", responseBody);
JSONObject bodyJson = JSON.parseObject(responseBody);
} else {
log.info("调用xxx接口失败:{}", responseBody);
}
}
GET请求
log.info("调用xxx接口请求链接 :{}", url);
try (
HttpResponse response = HttpRequest.get(url)
.header("Authorization", token)
.execute();
) {
String responseBody = response.body();
if (response.isOk()) {
log.info("调用xxx接口成功,返回数据:{}", responseBody);
JSONObject bodyJson = JSON.parseObject(responseBody);
} else {
log.info("xxx接口失败:{}", responseBody);
}
}