public void postSend(String reqJsonData, String documentCode, String userId) throws Exception {
CloseableHttpClient httpClient = HttpClients.createDefault();
String requestUrl = ConfigurationCache.getInstance().getValue(ConfigurationCache.REQUEST_SERVICE_URL);
HttpPost httpPost = new HttpPost(requestUrl + "/testapi/test/send");
httpPost.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8.toString());
httpPost.setEntity(new StringEntity(reqJsonData, "UTF-8"));
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpPost);
int errorCode = response.getStatusLine().getStatusCode();
logger.info("请求响应的状态:" + errorCode);
String responseResult = EntityUtils.toString(response.getEntity());
ResponseData responseData = XmlParseUtil.xmlToObj(responseResult, ResponseData.class, null);
logger.info("响应的结果:" + JSON.toJSONString(responseData));
response.close();
httpClient.close();
} catch (Exception e) {
logger.error("请求发生异常,原因:" , e);
if (response != null) {
response.close();
}
if (httpClient != null) {
httpClient.close();
}
}
}
HTTP发送POST请求
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
php POST的提交
pansw113
2019-02-22 23:13:02
嵌入式应用中CGI编程中POST、GET及环境变量详解
半點竹節
2019-02-22 23:13:00
都2019了,还在问GET和POST的区别
Android探索
2019-02-22 22:50:10
基于Python的HTTPS协议模拟登陆+爬取页面
風刃
2019-02-22 22:48:55
python模拟表单提交(一)
huanghongqiao
2019-02-22 14:53:04
跨站请求伪造CSRF防护方法
老鷹a
2019-02-23 00:37:33
请求转发和重定向的区别
北漂蒼狼
2019-02-22 22:35:56
C# Request请求——可用于WebService
objecttozero
2019-02-22 22:10:59
Jmeter源码之Http请求布局样式修改(三)
趙志忠
2019-02-22 20:44:46
nginx针对请求的uri来代理
小楊_Ivan
2019-02-22 17:05:15
一次完整的http请求过程
志_恆
2019-02-22 16:19:21
SpringMVC源码解读
刺激樂天派
2019-02-22 15:05:49