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