日期:2014-05-17  浏览次数:20672 次

发送post请求问题?
有哪位大牛指导一下,这个问题困扰我半天了!我在跟其他公司的一个系统进行对接时,给对方系统发送一个post的请求
这是我的写的方法:
try { 
URL url = new URL( "https://epcis-ptp-stg.dmzstg.pingan.com.cn:19443/epcis.ptp.partner.getAhsEPolicyPDFWithCert.do?"); 
URLConnection connection = url.openConnection(); 
connection.setDoOutput(true); 
//发送域信息 
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "8859_1"); 
out.write( "umCode="+umCode+"&validateCode="+validateCode+"&policyNo="+policyNo+"&isSeperated="+isSeperated+"&curTime="+curTime+"&signValue="+signValue);//这里组织域信息 
out.flush(); 
out.close(); 
//获取返回数据 
InputStream in = connection.getInputStream(); 

} catch (MalformedURLException e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 
} catch (UnsupportedEncodingException e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 
} catch (IOException e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 

调试后我发现:总在connection.getOutputStream()时出异常。说是证书方面的问题。错误提示是:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1476)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:847)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:815)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1025)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1038)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:402)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:170)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:836)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
at cn.com.caissa.erp.insurance.insbill.bs.impl.InsBillBs.getSignValue(InsBillBs.java:451)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)