public static String httpPost(Map<String, Object> requestBody, Map<String, String> requestHead, String url){
//发送post请求并接收响应数据
return cn.hutool.http.HttpUtil.createPost(url).addHeaders(requestHead).form(requestBody).execute().body();
}
public static void main(String[] args) {
Map<String, Object> tokenBody = null;
Map<String, String> requestHead = new HashMap<>();
String url = "http://api.user.mmcuav.cn/api/mmcuav/get-token";
tokenBody = new HashMap<>();
tokenBody.put("username","GSantai");
tokenBody.put("password","kbt@gs.antai2022");
String tokenResult = httpPost(tokenBody, requestHead, url);
System.out.println(tokenResult);
JSONObject result = JSONObject.parseObject(tokenResult);
String token = result.getString("token");
System.out.println("token: " + token);
// result.getJSONArray()
HashMap<String, String> header = new HashMap<>();
header.put("token", token);
System.out.println(httpPost(null, header, "http://api.user.mmcuav.cn/api/mmcuav/getuavlist"));
HashMap<String, Object> body = new HashMap<>();
body.put("deviceHardId","3769037989820971086");
System.out.println(httpPost(body, header, "http://api.user.mmcuav.cn/api/mmcuav/getuavdata"));
}
获取token
最新推荐文章于 2024-07-18 16:06:57 发布