前提 引入hutool依赖
具体实现
// 发送GET请求
public static HttpResponse sendGetRequest(String url, Map<String, List<String>> httpHeaders) {
HttpResponse response = HttpRequest.get(url)
.header(httpHeaders)
.execute();
return response;
}
// 发送POST请求(表单数据)
public static HttpResponse sendPostFormRequest(String url, String formData) {
HttpResponse response = HttpRequest.post(url)
.form(formData)
.execute();
return response;
}
// 发送POST请求(JSON数据)
public static HttpResponse sendPostJsonRequest(String url, Map<String, List<String>> headerMap, String jsonData) {
HttpResponse httpResponse = HttpRequest.post(url)
.header(headerMap)
.body(jsonData)
.execute();
return httpResponse;
}
// 发送PUT请求
public static HttpResponse sendPutRequest(String url, String jsonData) {
HttpResponse response = HttpRequest.put(url)
.header("Content-Type", "application/json")
.body(jsonData)
.execute();
return response;
}
标签:http,String,url,hutool,return,static,HttpResponse,response
From: https://www.cnblogs.com/xiaop27/p/18533275