当前位置:   article > 正文

获取token

获取token
  1. public static String httpPost(Map<String, Object> requestBody, Map<String, String> requestHead, String url){
  2. //发送post请求并接收响应数据
  3. return cn.hutool.http.HttpUtil.createPost(url).addHeaders(requestHead).form(requestBody).execute().body();
  4. }
  5. public static void main(String[] args) {
  6. Map<String, Object> tokenBody = null;
  7. Map<String, String> requestHead = new HashMap<>();
  8. String url = "http://api.user.mmcuav.cn/api/mmcuav/get-token";
  9. tokenBody = new HashMap<>();
  10. tokenBody.put("username","GSantai");
  11. tokenBody.put("password","kbt@gs.antai2022");
  12. String tokenResult = httpPost(tokenBody, requestHead, url);
  13. System.out.println(tokenResult);
  14. JSONObject result = JSONObject.parseObject(tokenResult);
  15. String token = result.getString("token");
  16. System.out.println("token: " + token);
  17. // result.getJSONArray()
  18. HashMap<String, String> header = new HashMap<>();
  19. header.put("token", token);
  20. System.out.println(httpPost(null, header, "http://api.user.mmcuav.cn/api/mmcuav/getuavlist"));
  21. HashMap<String, Object> body = new HashMap<>();
  22. body.put("deviceHardId","3769037989820971086");
  23. System.out.println(httpPost(body, header, "http://api.user.mmcuav.cn/api/mmcuav/getuavdata"));
  24. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/960225
推荐阅读
相关标签
  

闽ICP备14008679号