执行get提交 @param url 提交的URL @param headerMap 请求头集合 @return @throws IOException
(String url, Map<String, String> headerMap)
| 42 | * @throws IOException |
| 43 | */ |
| 44 | public HttpResult doGet(String url, Map<String, String> headerMap) throws IOException { |
| 45 | HttpGet httpGet = new HttpGet(url); |
| 46 | |
| 47 | |
| 48 | // httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); |
| 49 | if (headerMap != null && headerMap.size() >0) { |
| 50 | for (Map.Entry<String, String> entry : headerMap.entrySet()) { |
| 51 | httpGet.setHeader(entry.getKey(),entry.getValue());//键: Authorization 值: BEARER eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWQiOiI1LDE2Nzg4ZTMwMTEiLCJleHAiOjE1NTcyNDM0MzZ9.ZwhqVIbfFgtTB2ZDsFceXWzb2d5PjkuDGVqXB8IKoOw |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | //设置请求参数 |
| 56 | httpGet.setConfig(requestConfig); |
| 57 | |
| 58 | //创建httpClient对象 |
| 59 | CloseableHttpResponse response = null; |
| 60 | try { |
| 61 | //执行请求 |
| 62 | response = httpClient.execute(httpGet); |
| 63 | return new HttpResult(response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(),"UTF-8")); |
| 64 | } catch (IOException e) { |
| 65 | throw e; |
| 66 | } finally { |
| 67 | if (response != null) { |
| 68 | response.close(); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | |
| 74 | /** |