我尝试将XML表单发布到另一个网站,不幸的是有时成功错误(连接重置)?我可以知道导致连接重置的原因吗?没有超时问题,也没有连接问题。我该如何解决这个问题?
String rXML = "<?xml version='1.0' encoding='UTF-8'?><recordset><acmi><POL_NO>900-901-17-000012</POL_NO><ENDT_NO>0</ENDT_NO><EFF_DATE >2017-01-12</EFF_DATE ><EXP_DATE >2017-04-11</EXP_DATE ><GROSS_PREM >742.50</GROSS_PREM ><COMM_AMT >0.00</COMM_AMT ><COMM2_AMT >48.26</COMM2_AMT ><STAMP >10.00</STAMP ><AMT_DUE >797.05</AMT_DUE ><GST_PCT >6.00</GST_PCT ><GST_AMT >44.55</GST_AMT ><ADMIN_FEE >0.00</ADMIN_FEE ><OPERATOR >ACMI</OPERATOR ><CLIENT_NAME >TESTUSER</CLIENT_NAME ><DOB >2017-01-11</DOB ><SEX >C</SEX ><MARITAL >D</MARITAL ><CL_ADDR >TEST1,</CL_ADDR ><CL_POST_CODE >00000</CL_POST_CODE ><CL_CITY >TESTCITY</CL_CITY ><CL_STATE >BRU</CL_STATE ><CL_TEL_NO ></CL_TEL_NO ><CL_HP_NO ></CL_HP_NO ><BUSN_TEL_NO >1234567</BUSN_TEL_NO ><CL_EMAIL >abc@yahoo.com</CL_EMAIL ><BUSN_REG >BUSNREG087</BUSN_REG ><ISSUE_OFFICE >901</ISSUE_OFFICE ><MAINCLS >08</MAINCLS ><CLS >15</CLS ><SUBCLS >21</SUBCLS ><AGENT_ID >921MT</AGENT_ID ><AGENT_CODE >921</AGENT_CODE ><AGENT_CAT_TYPE >MT</AGENT_CAT_TYPE ><SOURCE_ID >1-D01</SOURCE_ID ><SOURCE_GRP >1</SOURCE_GRP ><SOURCE_CODE >D01</SOURCE_CODE ><ORC_ID >235MT</ORC_ID ><ORC_CODE >235</ORC_CODE ><ORC_CAT_TYPE >MT</ORC_CAT_TYPE ><REP_POL_NO ></REP_POL_NO ><POL_SEQ_CNT >1</POL_SEQ_CNT ><TRAN_DATE >2017-01-11</TRAN_DATE ><TRAN_TIME >2017-01-11 17:10:56.612</TRAN_TIME ><POL_SI >0.00</POL_SI ><COMM_PCT >0.00</COMM_PCT ><COMM2_PCT >6.50</COMM2_PCT ><OCCUP_CODE >02</OCCUP_CODE ><REGION >E</REGION ><PASSPORT ></PASSPORT ><NATIONALITY ></NATIONALITY ><CLM_EXP >3</CLM_EXP ><UWYR_MTH >01</UWYR_MTH ><UWYR_YEAR >2017</UWYR_YEAR ><FIN_YEAR >2017</FIN_YEAR ><ENDT_CNT >0</ENDT_CNT ><PRN_IND >0</PRN_IND ><AMT_DUE_ROUND >797.05</AMT_DUE_ROUND ><LEVY_PCT >0.00</LEVY_PCT ><LEVY_AMT >0.00</LEVY_AMT ><ANNUAL_PREM >742.50</ANNUAL_PREM ><STAX_PCT >0.00</STAX_PCT ><STAX_AMT >0.00</STAX_AMT ><AFTCOMM_PREM >748.79</AFTCOMM_PREM ><GEOG_AREA >A7</GEOG_AREA ><COUNTRY_ORIGIN >BRU</COUNTRY_ORIGIN ><COUNTRY_DEPARTURE >BRU</COUNTRY_DEPARTURE ><COUNTRY_DESTINATION >CBD</COUNTRY_DESTINATION ><CB_NO >CB085</CB_NO ><COUNTRY_CODE >BRU</COUNTRY_CODE ><ALT_EMAIL ></ALT_EMAIL ><PURPOSE >B</PURPOSE ><DRVR_IND ></DRVR_IND ><EFF_TIME >00:00:00</EFF_TIME ><PXPAY_DPSTXNREF ></PXPAY_DPSTXNREF ><PXPAY_CRNAME ></PXPAY_CRNAME ><PXPAY_CRCARD ></PXPAY_CRCARD ><RCPT_NO >MMIP20000000012</RCPT_NO ><RCPT_DATE >2017-01-11</RCPT_DATE ><RCPT_AMT >797.05</RCPT_AMT ><RISK_SEQ_NO >1</RISK_SEQ_NO ><SI >0.00</SI ><ARIDER_PREM >0.00</ARIDER_PREM ><LOAD_AMT >445.50</LOAD_AMT ><NCB_AMT >0.00</NCB_AMT ><BASIC_PREM >297.00</BASIC_PREM ><ACT_PREM >663.30</ACT_PREM ><ACT_APREM >265.32</ACT_APREM ><EXCESS_AMT >5000.00</EXCESS_AMT ><REFER_LOAD_AMT >0.00</REFER_LOAD_AMT ><REFER_EXCESS >0.00</REFER_EXCESS ><ITM_NO >1</ITM_NO ><VEH_NO >VEH087</VEH_NO ><LOAD_PCT >150.0</LOAD_PCT ><VEH_MODEL >99</VEH_MODEL ><VEH_MAKE >26</VEH_MAKE ><VEH_BODY >06</VEH_BODY ><CAPACITY >01</CAPACITY ><CAPACITY_AMT >2000.00</CAPACITY_AMT ><UOM >KG</UOM ><USE_LIMIT >M.Z.301</USE_LIMIT ><PASSENGER_CNT >5</PASSENGER_CNT ><YEAR_MAKE >2000</YEAR_MAKE ><ENGINE_NO >ENGINE087</ENGINE_NO ><CHASSIS_NO >CHASSIS087</CHASSIS_NO ><REG_TYPE >R</REG_TYPE ><COVERAGE >02</COVERAGE ><SPECIAL_TYPE >NA</SPECIAL_TYPE ><CLAUSE >3P,LDC</CLAUSE ><WARR >W1,W2,W3,W4CV,W5CV,W6,W7,W8</WARR ><RISK_CODE >2</RISK_CODE ><VEH_TYPE >F</VEH_TYPE ><EXCESS_PCT >0.00</EXCESS_PCT ><ARIDER_PCT >0.00</ARIDER_PCT ><REFER_LOAD_PCT >0.00</REFER_LOAD_PCT ><MARKET_VALUE >0.00</MARKET_VALUE ><EXCESS_CODE >03</EXCESS_CODE ><NCB_PCT >0.00</NCB_PCT ><EXTCOV_PREM >0.00</EXTCOV_PREM ><NCB_CODE >00</NCB_CODE ><NCB_EFF_DATE >2018-01-12</NCB_EFF_DATE ><NAMED_DRVR_1>TESTA</NAMED_DRVR_1><DRVR_PASSPORT_1>passporta</DRVR_PASSPORT_1><DRVR_DOB_1>1990-01-01</DRVR_DOB_1><DRVR_GENDER_1>M</DRVR_GENDER_1><NAMED_DRVR_2></NAMED_DRVR_2><DRVR_PASSPORT_2></DRVR_PASSPORT_2><DRVR_DOB_2></DRVR_DOB_2><DRVR_GENDER_2></DRVR_GENDER_2><NAMED_DRVR_3></NAMED_DRVR_3><DRVR_PASSPORT_3></DRVR_PASSPORT_3><DRVR_DOB_3></DRVR_DOB_3><DRVR_GENDER_3></DRVR_GENDER_3><NAMED_DRVR_4></NAMED_DRVR_4><DRVR_PASSPORT_4></DRVR_PASSPORT_4><DRVR_DOB_4></DRVR_DOB_4><DRVR_GENDER_4></DRVR_GENDER_4><TRL_NO></TRL_NO><TRL_CHASSIS_NO></TRL_CHASSIS_NO><TRL_SI>0.00</TRL_SI><TRL_PREM>0.00</TRL_PREM><TRL_ACT_PREM>0.00</TRL_ACT_PREM><TRL_APREM>0.00</TRL_APREM><TRL_ACT_APREM>0.00</TRL_ACT_APREM></acmi></recordset>";
String sURL = "https://drc.mmip.com.my/iimsweb_uw/acmi/UTIL_ACMIOUTPUT.jsp";
String sXML = postXML.httpsposting(sURL,rXML);
public String httpsposting(String sURL, String sXML)
{
try
{
Security.addProvider(new com.ibm.jsse.IBMJSSEProvider());
System.setProperty("java.protocol.handler.pkgs", "com.ibm.net.ssl.internal.www.protocol");
SSLSocketFactory factory = null;
javax.net.ssl.SSLContext ctx;
javax.net.ssl.KeyManagerFactory kmf;
javax.net.ssl.TrustManagerFactory tmf;
TrustManager[] tms = {new MyTrustManager()};
KeyStore ksSvr = KeyStore.getInstance("JKS");
ksSvr.load(null, null);
java.security.cert.CertificateFactory cf = CertificateFactory.getInstance("X.509");
//Get certificate from file (Export from IE)
java.security.cert.Certificate serverCert =
cf.generateCertificate(new FileInputStream(cert_path + "/" + cert_name));
ksSvr.setCertificateEntry("server", serverCert);
char[] passphrase = cert_pass.toCharArray();
kmf = javax.net.ssl.KeyManagerFactory.getInstance("IbmX509");//SunX509
kmf.init(ksSvr, passphrase);
tmf = javax.net.ssl.TrustManagerFactory.getInstance("IbmX509");
tmf.init(ksSvr);
ctx = com.ibm.jsse.SSLContext.getInstance("TLSv1");
ctx.init(kmf.getKeyManagers(), tms, null);
factory = ctx.getSocketFactory();
java.net.URL url = new java.net.URL(sURL);
//CPW 12/11/2007 - WAS6
//com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection https = (com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection) url.openConnection();
boolean bWAS5 = false;
try
{
javax.net.ssl.HttpsURLConnection httpstest = (javax.net.ssl.HttpsURLConnection) url.openConnection();
}
catch (Exception e)
{
bWAS5 = true;
}
javax.net.ssl.HttpsURLConnection https = (javax.net.ssl.HttpsURLConnection) url.openConnection();
https.setSSLSocketFactory(factory);
https.setRequestMethod("POST");
https.setDoInput(true);
https.setDoOutput(true);
// In this example we send a text file by the POST.
https.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
DataOutputStream out = new DataOutputStream(https.getOutputStream());
out.writeBytes (sXML);
BufferedReader in = new BufferedReader(new InputStreamReader(https.getInputStream()));
String inputLine;
StringBuffer sb = new StringBuffer();
while ((inputLine = in.readLine()) != null)
{
sb.append(inputLine);
sb.append("^");
}
in.close();
out.close();
return sb.toString();
}
catch (Exception e)
{
e.printStackTrace();
return "ERROR";
}
}