执行put请求 @param url URL地址 @param headerMap 请求头参数 @return @throws IOException
(String url,Map<String, String> headerMap)
| 242 | * @throws IOException |
| 243 | */ |
| 244 | public HttpResult doPut(String url,Map<String, String> headerMap) throws IOException { |
| 245 | HttpPut httpPut = new HttpPut(url); |
| 246 | |
| 247 | //设置请求参数 |
| 248 | httpPut.setConfig(requestConfig); |
| 249 | |
| 250 | if (headerMap != null && headerMap.size() >0) { |
| 251 | for (Map.Entry<String, String> entry : headerMap.entrySet()) { |
| 252 | httpPut.setHeader(entry.getKey(),entry.getValue());//键: Authorization 值: BEARER eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWQiOiI1LDE2Nzg4ZTMwMTEiLCJleHAiOjE1NTcyNDM0MzZ9.ZwhqVIbfFgtTB2ZDsFceXWzb2d5PjkuDGVqXB8IKoOw |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | //创建httpClient对象 |
| 257 | CloseableHttpResponse response = null; |
| 258 | try { |
| 259 | //执行请求 |
| 260 | response = httpClient.execute(httpPut); |
| 261 | |
| 262 | return new HttpResult(response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(), "UTF-8")); |
| 263 | } finally { |
| 264 | if (response != null) { |
| 265 | response.close(); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * 将url参数转换成map |