代码如下:package com.wisher.https.test;import java.io.IOException;import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.protocol.Protocol;public class HttpsPostTest {
private static final String URL = "https://10.76.112.103:447/vmx";

public static void main(String[] args) {
PostMethod post = null;
/*Protocol https = new Protocol("https", new EasySSLProtocolSocketFactory(), 447);
Protocol.registerProtocol("https", https);
System.out.println("Https Protocol has registered...");*/

try {
post = new PostMethod(URL);
System.out.println("URL : " + post.getURI());
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
RequestEntity entity = new ByteArrayRequestEntity(Common.getDocument().getBytes(), "text/xml; charset=UTF-8");
post.setRequestEntity(entity);
post.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
int result = client.executeMethod(post);
System.out.println(result);
System.out.println(post.getResponseBodyAsString());
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
post.releaseConnection();
}
}
}这段代码直接运行可以得到反馈,但是部署在Websphere上就在int result = client.executeMethod(post);这一句终止了
,拿不到返回码,之后的事情也处理不了
备注:直接java工程运行的时候不需要下面两句都可以成功
Protocol https = new Protocol("https", new EasySSLProtocolSocketFactory(), 447);
Protocol.registerProtocol("https", https);但是不熟到websphere就需要上面两句