/**
* <p>描述: 使用HttpPost传输 有用户名密码验证的xml格式的WebService调用</p>
*
* @param url webservice的URL
* @param xmlStr xml格式的数据字符串
* @return 返回传输响应的结果字符串
*/
public static String postXMLAuthWithHttpPost(String url, String xmlStr) {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpEntity entity = null;
HttpEntity Rentity = null;
String retStr = "";
CloseableHttpResponse response = null;
try {
entity = new StringEntity(xmlStr, "UTF-8");
HttpPost hp = new HttpPost(url);
hp.addHeader("Content-Type", "application/soap+xml;charset=UTF-8");
hp.setEntity(entity);
response = httpclient.execute(hp);
Rentity = response.getEntity();
if (Rentity != null) {
retStr = EntityUtils.toString(Rentity, "UTF-8");
}
} catch (Exception e) {
} finally {
HTTP方式Post通信发送报文
最新推荐文章于 2025-06-03 16:55:46 发布