diff --git a/op-common/op-common-core/src/main/java/com/op/common/core/constant/ServiceNameConstants.java b/op-common/op-common-core/src/main/java/com/op/common/core/constant/ServiceNameConstants.java index 6a783069..ec2d8c09 100644 --- a/op-common/op-common-core/src/main/java/com/op/common/core/constant/ServiceNameConstants.java +++ b/op-common/op-common-core/src/main/java/com/op/common/core/constant/ServiceNameConstants.java @@ -50,4 +50,9 @@ public class ServiceNameConstants { public static final String DEVICE_SERVICE = "op-device"; /**质量模块**/ public static final String QMS_SERVICE = "op-quality"; + + /** + * 接口模块的serviceid + */ + public static final String OPEN_SERVICE = "op-open"; } diff --git a/op-common/op-common-core/src/main/java/com/op/common/core/utils/http/HttpUtils.java b/op-common/op-common-core/src/main/java/com/op/common/core/utils/http/HttpUtils.java index 15833cf5..cc474c45 100644 --- a/op-common/op-common-core/src/main/java/com/op/common/core/utils/http/HttpUtils.java +++ b/op-common/op-common-core/src/main/java/com/op/common/core/utils/http/HttpUtils.java @@ -120,6 +120,62 @@ public class HttpUtils { return result.toString(); } + /** + * 向指定 URL 发送POST方法的请求 + * + * @param url 发送请求的 URL + * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 + * @return 所代表远程资源的响应结果 + */ + public static String sendPostOA(String url, String param) { + PrintWriter out = null; + BufferedReader in = null; + StringBuilder result = new StringBuilder(); + try { + String urlNameString = url + "?" + param; + log.info("sendPost - {}" , urlNameString); + URL realUrl = new URL(urlNameString); + URLConnection conn = realUrl.openConnection(); + conn.setRequestProperty("accept" , "*/*"); + conn.setRequestProperty("connection" , "Keep-Alive"); + conn.setRequestProperty("user-agent" , "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + conn.setRequestProperty("Accept-Charset" , "utf-8"); +// conn.setRequestProperty("contentType" , "utf-8"); + conn.setRequestProperty("content-Type", "application/json; charset=GBK"); + conn.setDoOutput(true); + conn.setDoInput(true); + out = new PrintWriter(conn.getOutputStream()); + out.print(param); + out.flush(); + in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "GBK")); + String line; + while ((line = in.readLine()) != null) { + result.append(line); + } + log.info("recv - {}" , result); + } catch (ConnectException e) { + log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e); + } catch (SocketTimeoutException e) { + log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e); + } catch (IOException e) { + log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e); + } catch (Exception e) { + log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e); + } finally { + try { + if (out != null) { + out.close(); + } + if (in != null) { + in.close(); + } + } catch (IOException ex) { + log.error("调用in.close Exception, url=" + url + ",param=" + param, ex); + } + } + return result.toString(); + } + public static String sendSSLPost(String url, String param) { StringBuilder result = new StringBuilder(); String urlNameString = url + "?" + param;