kongzy
2024-06-24 4910e41f81a85c03a9dfc83f8ec9c1e71c123d49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.gkhy.exam.common.utils;
 
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
 
import java.util.HashMap;
import java.util.Map;
 
@Slf4j
public class HttpUtils {
 
    public static String sendGet(String url, Map<String, Object> queryParams){
        Map<String, String> headers =new HashMap<>();
        headers.put("accept","*/*");
        headers.put("connection","Keep-Alive");
        headers.put("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
        String body="";
        try {
            body = HttpRequest.get(url).form(queryParams).addHeaders(headers).execute().body();
            log.info("recv - {}",body);
            return body;
        }catch (HttpException e){
            log.error("调用HttpUtils.sendGet ConnectException, url=" + url + ",param=" + JSON.toJSONString(queryParams), e);
        }
        return body;
    }
}