vince
2025-03-06 88763f2ae21e9d3771ba744577edcc2d344802a6
src/main/java/com/fzzy/push/gb2022/HttpClientUtil.java
@@ -21,14 +21,15 @@
    /**
     * post formData
     *
     * @param url
     * @param map
     * @return
     * @throws Exception
     */
    @SuppressWarnings("resource")
   public static ResponseDto postFormData(String url, Map<String, Object> map) throws Exception {
        log.info("---------接口请求地址:" +url+ "----------参数:" + JSON.toJSONString(map) +"---------");
    public static ResponseDto postFormData(String url, Map<String, Object> map) throws Exception {
        log.info("---------接口请求地址:" + url + "----------参数:" + JSON.toJSONString(map) + "---------");
        BufferedReader in = null;
        URL urls = new URL(url);
        HttpURLConnection connection = null;
@@ -47,10 +48,10 @@
            connection.setConnectTimeout(20000);
            connection.setReadTimeout(30000);
            connection.setRequestMethod("POST");
            if(StringUtils.isNotEmpty(JSESSIONID)){
            if (StringUtils.isNotEmpty(JSESSIONID)) {
//                connection.setRequestProperty("Cookie", "JSESSIONID="+JSESSIONID);
//                connection.setRequestProperty(" Set-Cookies", JSESSIONID);
                connection.setRequestProperty("Cookie", "JSESSIONID="+JSESSIONID);
                connection.setRequestProperty("Cookie", "JSESSIONID=" + JSESSIONID);
            }
            map.remove("JSESSIONID");
@@ -76,7 +77,7 @@
//                    System.out.println(buffer.toString());
                    outputStream.write(buffer.toString().getBytes());
                    File file = (File) entry.getValue();
                   DataInputStream ins = new DataInputStream(new FileInputStream(file));
                    DataInputStream ins = new DataInputStream(new FileInputStream(file));
                    int bytes = 0;
                    byte[] bufferOut = new byte[1024];
                    while ((bytes = ins.read(bufferOut)) != -1) {
@@ -102,7 +103,7 @@
                    while ((line = in.readLine()) != null) {
                        rs += line;
                    }
                }else{
                } else {
                    log.error("http状态:" + connection.getResponseCode());
                    log.error("http消息:" + connection.getResponseMessage());
                }
@@ -110,7 +111,7 @@
                String serverCookies = connection.getHeaderField("Set-Cookie");
                log.info("serverCookies:" + serverCookies);
                if(serverCookies != null) {
                if (serverCookies != null) {
                    String[] cookies = serverCookies.split(";");
@@ -128,19 +129,19 @@
            } catch (Exception e) {
                System.out.println("发生异常");
                log.error(e.getMessage(),e);
                log.error(e.getMessage(), e);
                rs = null;
                return new ResponseDto(99,e.getMessage());
                return new ResponseDto(99, e.getMessage());
            }
            log.info("---------接口返回:" + rs +"---------");
            responseDto = JSON.parseObject(rs,ResponseDto.class);
            if(responseDto == null )   return new ResponseDto(99,"接口请求发生未知错误");
            log.info("---------接口返回:" + rs + "---------");
            responseDto = JSON.parseObject(rs, ResponseDto.class);
            if (responseDto == null) return new ResponseDto(99, "接口请求发生未知错误");
            responseDto.setJSESSIONID(JSESSIONID);
            return responseDto;
        } finally {
            try {
                outputStream.close();
                if (in != null){
                if (in != null) {
                    in.close();
                }
            } catch (Exception e) {