From caf2599a9869244ded811018811c37a2aabac3fc Mon Sep 17 00:00:00 2001 From: vince <757871790@qq.com> Date: 星期三, 08 一月 2025 11:29:05 +0800 Subject: [PATCH] 优化测温协议 --- src/main/java/com/fzzy/push/gb2022/HttpClientUtil.java | 27 ++++++++++++++------------- 1 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/fzzy/push/gb2022/HttpClientUtil.java b/src/main/java/com/fzzy/push/gb2022/HttpClientUtil.java index b1484ff..b52cd8e 100644 --- a/src/main/java/com/fzzy/push/gb2022/HttpClientUtil.java +++ b/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) { -- Gitblit v1.9.3