package com.stylefeng.guns.modular.system.utils.PortUtil; import cn.hutool.http.HttpRequest; import com.stylefeng.guns.core.common.exception.BizExceptionEnum; import com.stylefeng.guns.core.exception.GunsException; import com.stylefeng.guns.modular.system.warpper.TerminaleDataWarpper; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class FMSStrategy implements WharfStrategy { @Override public TerminaleDataWarpper executeLogic(String... params) { String enums = ""; if (params.length == 0) { throw new GunsException(BizExceptionEnum.REQUEST_EMPTY_ERROR); } else { enums = params[0]; } HttpRequest httpRequest = HttpRequest.get("http://n4.fenixmarineservices.com:9081/apex/api/codeextension?extensionname=FenixCheckCtrAvailability&operatorId=FMS&complexId=USSPQ&facilityId=FMS&yardId=FMS&PARM_filterName=UNIT_FINDER_QUERY&PARM_CTRNBR=" + enums); System.out.println(httpRequest); return null; } public static void main(String[] args) throws Exception { String post = post("http://n4.fenixmarineservices.com:9081/apex/api/codeextension?extensionname=FenixCheckCtrAvailability&operatorId=FMS&complexId=USSPQ&facilityId=FMS&yardId=FMS&PARM_filterName=UNIT_FINDER_QUERY&PARM_CTRNBR=" + "TGHU9229633", ""); System.out.println(post); } public static String post(String strURL, String params) throws Exception { System.out.println(strURL); System.out.println(params); String result = ""; BufferedReader reader = null; try { URL url = new URL(strURL);// 创建连接 HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestMethod("GET"); // 设置请求方式 connection.setRequestProperty("Accept", "application/json"); // 设置接收数据的格式 connection.setRequestProperty("Content-Type", "application/json"); // 设置发送数据的格式 connection.connect(); if (connection.getResponseCode() == 200) { reader = new BufferedReader( new InputStreamReader(connection.getInputStream())); result = reader.readLine(); } else { throw new Exception(connection.getResponseMessage()); } } catch (Exception e) { throw new Exception("http的post请求异常!" + e.getMessage()); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; } }