1、get请求
String url = "接口地址";
String data = HttpRequest.get(url)
// 超时,毫秒
.timeout(4000)
.execute().body();
// 将返回的data数据反序列化
DtJqGxRequest res = JSON.parseObject(data, DtJqGxRequest.class);
2.post请求
String url = "接口地址";
//json字符串
Map p = new HashMap();
p.put("uname", "账号");
p.put("pwd", "密码");
// 创建存放参数的集合
Map<String, Object> map = new HashMap<>();
map.put("data", JSONObject.toJSONString(p));
// 发送http请求获取token
String result = HttpRequest.post(url)
.form(map)
// 超时,毫秒
.timeout(20000)
.execute().body();
List<Map> list = objectMapper.readValue(result, List.class);
String durl = "地址";
Map<String, Object> params1 = new HashMap<>();
params1.put("deviceSerial", tokenResource);
String s1 = JSONObject.toJSONString(params1);
try {
String result1 = HttpRequest.post(durl)
.header("Authorization", accessToken)
.body(s1)
// 超时,毫秒
.timeout(20000)
.execute().body();
} catch (Exception e) {
log.error(失败");
}