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

Method doGet

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

执行get请求,200返回响应内容,其他状态码返回null @param url URL地址 @return @throws IOException

(String url)

Source from the content-addressed store, hash-verified

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请求

Callers 1

queryOtherUserInfoMethod · 0.45

Calls 2

getMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected