From 757ee5dc2ca4185d3c60db1e8c35d2e96e15c50c Mon Sep 17 00:00:00 2001 From: CZT <czt18638530771@163.com> Date: 星期四, 14 十二月 2023 17:35:46 +0800 Subject: [PATCH] 上海省平台共享接口-监控信息更新 --- src/main/java/com/fzzy/push/sh2023/SH2023HttpClientUtil.java | 72 +++++++++++++++++++++++++++++++++++ 1 files changed, 71 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/fzzy/push/sh2023/SH2023HttpClientUtil.java b/src/main/java/com/fzzy/push/sh2023/SH2023HttpClientUtil.java index 9f5ddf9..bbaef44 100644 --- a/src/main/java/com/fzzy/push/sh2023/SH2023HttpClientUtil.java +++ b/src/main/java/com/fzzy/push/sh2023/SH2023HttpClientUtil.java @@ -2,7 +2,7 @@ import com.alibaba.fastjson.JSON; import com.fzzy.api.entity.ApiConfs; -import com.fzzy.push.sh2023.dto.SH2023ReqDto; +import com.fzzy.push.sh2023.dto.SH2023PullRespDto; import com.fzzy.push.sh2023.dto.SH2023RespDto; import lombok.extern.slf4j.Slf4j; import java.io.BufferedReader; @@ -87,4 +87,74 @@ connection = null; } } + + /** + * 鎷夊彇鏁版嵁 + * @param url + * @param reqData + * @return + * @throws Exception + */ + @SuppressWarnings("resource") + public static SH2023PullRespDto postPullData(String url, String reqData) throws Exception { + log.info("---------鎺ュ彛璇锋眰鍦板潃锛�" +url+ "----------鍙傛暟锛�" + reqData +"---------"); + BufferedReader in = null; + URL urls = new URL(url); + HttpURLConnection connection = null; + OutputStream outputStream = null; + String rs = ""; + SH2023PullRespDto responseDto; + try { + + connection = (HttpURLConnection) urls.openConnection(); + connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8"); + connection.setRequestProperty("Accept", "*/*"); + connection.setRequestProperty("Range", "bytes=" + ""); + connection.setConnectTimeout(20000); + connection.setReadTimeout(30000); + connection.setRequestMethod("POST"); + + outputStream = connection.getOutputStream(); + + outputStream.write(reqData.getBytes("UTF-8")); + try { + connection.connect(); + if (connection.getResponseCode() == 200) { + in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); + String line = ""; + while ((line = in.readLine()) != null) { + rs += line; + } + }else{ + log.error("http鐘舵�侊細" + connection.getResponseCode()); + log.error("http娑堟伅锛�" + connection.getResponseMessage()); + } + + } catch (Exception e) { + System.out.println("鍙戠敓寮傚父"); + log.error(e.getMessage(),e); + rs = null; + return new SH2023PullRespDto(99,e.getMessage(),null,null,null); + } + log.info("---------鎺ュ彛杩斿洖锛�" + rs +"---------"); + responseDto = JSON.parseObject(rs,SH2023PullRespDto.class); + if(responseDto == null ) return new SH2023PullRespDto(99,"鎺ュ彛璇锋眰鍙戠敓鏈煡閿欒",null,null,null); + return responseDto; + } finally { + try { + outputStream.close(); + if (in != null){ + in.close(); + } + } catch (Exception e) { + } + outputStream = null; + if (connection != null) + connection.disconnect(); + connection = null; + } + } } \ No newline at end of file -- Gitblit v1.9.3