zoukankan      html  css  js  c++  java
  • Hutools之http工具类

    Hutools请求网络资源使用的工具类:HttpRequest和HttpResponse

    Get方式请求数据

    Get方式请求数据
    Map<String,Object> paramMap = new HashMap<>(); //map中带不带参数都可以这样用 HttpResponse httpResponse
    = HttpRequest.get(url).form(paramMap).timeout(time * 1000).execute(); int status = httpResponse.getStatus(); System.out.println(httpResponse.body());

    POST方式请求数据

    (1)x-www-form-urlencoded形式的参数
      Map<String,Object> paramMap = new HashMap<>();
      HttpResponse httpResponse = HttpRequest.post(url).form(paramMap).timeout(time * 1000).execute();
       int status = httpResponse.getStatus();
    (2)application/json形式的参数
      Map<String,Object> paramMap = new HashMap<>();
      paramMap.put("username,"jerry");
      Gson gson = new Gson();
      String param = hson.toJson(paramMap);  //转换json数据
      HttpResponse httpResponse = HttpRequest.post(url).body(param , "application/json").timeout(time * 1000).execute();
      int status = httpResponse.getStatus

    PUT方式请求数据(与POST方式的请求雷同)

  • 相关阅读:
    mybatis-generator.xml
    模板下载
    任务导出
    订单导出
    创建指定日期任务
    字符串的知识
    数组元素反转
    JVM 中知识
    Redis介绍
    JsonP
  • 原文地址:https://www.cnblogs.com/shirandedan/p/9455730.html
Copyright © 2011-2022 走看看