执行get请求,200返回响应内容,其他状态码返回null @param url URL地址 @return @throws IOException
(String url)
| 51 | * @throws IOException |
| 52 | */ |
| 53 | public String doGet(String url) throws IOException { |
| 54 | //创建httpClient对象 |
| 55 | CloseableHttpResponse response = null; |
| 56 | HttpGet httpGet = new HttpGet(url); |
| 57 | //设置请求参数 |
| 58 | httpGet.setConfig(requestConfig); |
| 59 | try { |
| 60 | //执行请求 |
| 61 | response = httpClient.execute(httpGet); |
| 62 | //判断返回状态码是否为200 |
| 63 | if (response.getStatusLine().getStatusCode() == 200) { |
| 64 | return EntityUtils.toString(response.getEntity(), "UTF-8"); |
| 65 | } |
| 66 | } finally { |
| 67 | if (response != null) { |
| 68 | response.close(); |
| 69 | } |
| 70 | } |
| 71 | return null; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * 执行带有参数的get请求 |
no test coverage detected