赞
踩
- 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"));
-
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。