标签:pre 工具类 json sys .exe bsp too system color
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方式的请求雷同)
标签:pre 工具类 json sys .exe bsp too system color
原文地址:https://www.cnblogs.com/shirandedan/p/9455730.html