危化品全生命周期管理后端
kongzy
2024-08-22 0c73654f55844e34772732914af8cc1e247aab63
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.hazmat.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;
    }
}