/**
*
* @param sendXml
* 需要發送的報文字符串
* @param requestUrl
* 請求url地址
* @return 響應報文字符串
*/
public static String sendSOAP(String sendXml, String requestUrl) {
String responseBodySOAP = null;
byte[] requestBytes;
try {
// 請求發送前給系統添加參數,JKS證書
System.setProperty("javax.net.ssl.trustStore", csj.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "123456");
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("javax.net.ssl.keyStore",csj.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "123456");
requestBytes = sendXml.getBytes();
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod(requestUrl);
InputStream inputStream = new ByteArrayInputStream(requestBytes, 0, requestBytes.length);
RequestEntity requestEntity = new InputStreamRequestEntity(inputStream, requestBytes.length,
"application/soap+xml; charset=utf-8");
postMethod.setRequestEntity(requestEntity);
System.out.println("請求報文:" + sendXml);
httpClient.executeMethod(postMethod);
// responseBodySOAP = postMethod.getResponseBodyAsString();
BufferedReader br = new BufferedReader(
new InputStreamReader(postMethod.getResponseBodyAsStream(), "utf-8"));
String responseLine = "";
StringBuffer sb = new StringBuffer();
for (responseLine = br.readLine(); responseLine != null; responseLine = br.readLine()) {
sb.append(responseLine);
}
br.close();
responseBodySOAP = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("響應報文:" + responseBodySOAP);
return responseBodySOAP;
}
使用Apache提供的HttpClient發送https請求
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
一篇文章爲你深度解析HTTPS 協議
何奧雷
2019-02-23 00:14:52
Spring Boot HTTPS配置與後臺調用
Jason_川川
2019-02-22 23:46:42
SSL證書常見錯誤和解決辦法
CTMO
2019-02-22 23:31:42
哪些網站需要HTTPS(SSL證書),至關重要嗎?
CTMO
2019-02-22 23:31:42
基於Python的HTTPS協議模擬登陸+爬取頁面
風刃
2019-02-22 22:48:55
PHP筆記
wq2010feng
2019-02-22 22:26:46
使用騰訊雲大禹開啓全站HTTPS
李是個好人
2019-02-22 20:42:25
用信鴿來解釋 HTTPS
套路走不穿
2019-02-22 19:58:42
WordPress博客DUX主題如何開啓全站HTTPS?
wenm945
2019-02-22 19:52:22
HTTPS基本原理與應用
lilugoodjob
2019-02-22 18:44:03
Java調用https服務報錯unable to find valid certification path to requested target的解決方法
after_sss
2019-02-22 18:34:21
Nginx配置SSL證書部署HTTPS網站
尤濤
2019-02-22 16:56:11
申請https協議總結
往事如風sag
2019-02-22 16:12:03
HttpClient學習
longlongchang
2019-02-22 19:46:57
記錄一次解決httpcline請求https報handshake_failure錯誤
bipig0724
2019-02-22 19:36:49
24小時熱門文章