MCPcopy Create free account
hub / github.com/diyhi/bbs / doPost

Method doPost

src/main/java/cms/component/HttpClientComponent.java:99–128  ·  view source on GitHub ↗

执行post请求 @param url URL地址 @param paramMap 请求参数 @return @throws IOException

(String url, Map<String, String> paramMap)

Source from the content-addressed store, hash-verified

97 * @throws IOException
98 */
99 public HttpResult doPost(String url, Map<String, String> paramMap) throws IOException {
100 HttpPost httpPost = new HttpPost(url);
101
102
103 // httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
104
105 //设置请求参数
106 httpPost.setConfig(requestConfig);
107 if (paramMap != null) {
108 List<NameValuePair> parameters = new ArrayList<NameValuePair>();
109 for (String s : paramMap.keySet()) {
110 parameters.add(new BasicNameValuePair(s, paramMap.get(s)));
111 }
112 //构建一个form表单式的实体
113 UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(parameters, Charset.forName("UTF-8"));
114 //将请求实体放入到httpPost中
115 httpPost.setEntity(formEntity);
116 }
117 //创建httpClient对象
118 CloseableHttpResponse response = null;
119 try {
120 //执行请求
121 response = httpClient.execute(httpPost);
122 return new HttpResult(response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(), "UTF-8"));
123 } finally {
124 if (response != null) {
125 response.close();
126 }
127 }
128 }
129
130 /**
131 * 执行post请求

Callers 4

queryWeiXinOpenIdMethod · 0.45
queryWeiXinUserInfoMethod · 0.45
queryOtherAccessTokenMethod · 0.45

Calls 3

getMethod · 0.80
addMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected