2024年6月11日发(作者:)
// }
// HttpResponse httpResponse = e(httpPost);
// int statusCode = tusLine().getStatusCode();
// n("状态码:" + statusCode);
// if (statusCode == _OK) {
// HttpEntity resEntity = ity();
// result = ng(resEntity);
// } else {
// readHttpResponse(httpResponse);
// }
// } catch (Exception e) {
// throw e;
// } finally {
// if (httpClient != null) {
// ();
// }
// }
// return result;
// }
public static String postXML(String url,String xml){
CloseableHttpClient client = null;
CloseableHttpResponse resp = null;
try{
HttpPost httpPost = new HttpPost(url);
der("Content-Type", "text/xml; charset=UTF-8");
client = Default();
StringEntity entityParams = new StringEntity(xml,"utf-8");
ity(entityParams);
client = Default();
resp = e(httpPost);
String resultMsg = ng(ity(),"utf-8");
return resultMsg;
}catch (Exception e){
tackTrace();
}finally {
try {
if(client!=null){
();
}
if(resp != null){
();
}
} catch (IOException e) {
tackTrace();
}
}
return null;
}
public static CloseableHttpClient getHttpClient() throws Exception {
CloseableHttpClient httpClient = ().setSSLSocketFactory(sslsf).setConnectionManager(cm)
.setConnectionManagerShared(true).build();
return httpClient;
}
public static String readHttpResponse(HttpResponse httpResponse) throws ParseException, IOException {
StringBuilder builder = new StringBuilder();
// 获取响应消息实体
HttpEntity entity = ity();
// 响应状态
("status:" + tusLine());
("headers:");
HeaderIterator iterator = Iterator();
while (t()) {
("t" + ());
}
// 判断响应实体是否为空
if (entity != null) {
String responseString = ng(entity);
("response length:" + ());
("response content:" + e("rn", ""));
}
return ng();
}
/**
* get发送数据
* @param url
* @param param
* @return
*/
public static String doGet(String url, Map
发布评论