路泰机电科技体检——数据平台后端
zhaowenxuan
2025-06-12 493d39e60bae93a724448af7dd53e2ff10b927c8
src/main/java/com/example/utils/HttpClientUtils.java
@@ -97,7 +97,7 @@
    }
    public static String sendPost(String httpUrl, Map<String, Object> maps) {
    public static String sendPost(String httpUrl, Map<String, Object> maps,Map<String ,Object> headers) {
        try {
            // 1. 创建 URL 对象
@@ -108,11 +108,17 @@
            connection.setRequestMethod("POST");
            // 4. 设置 Content-Type 头部字段
            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
            if (headers != null && !headers.isEmpty()){
                for (Map.Entry<String, Object> entry : headers.entrySet()) {
                    connection.setRequestProperty(entry.getKey(), entry.getValue().toString());
                }
            }
            // 6. 向服务器发送数据
            String requestBody = JSONUtil.toJsonStr(maps);
            log.info(httpUrl+"入参:   "+requestBody);
            log.info("请求头 ->{}",JSONUtil.toJsonStr(headers));
//            String requestBody1 = maps.toString();
            byte[] postData = requestBody.getBytes("UTF-8");
            byte[] postData = requestBody.getBytes(StandardCharsets.UTF_8);
            connection.setDoOutput(true);
            try (OutputStream outputStream = connection.getOutputStream()) {
                outputStream.write(postData);