Apache httpcomponents-client - CloseableHttpResponse方法不起作用

时间:2017-05-28 04:46:14

标签: java apache-httpclient-4.x

我目前正在http client中构建一个非常简单的Netbeans 8.2,并希望使用Apache httpcomponents-client 4.5库。在我尝试使用CloseableHttpResponse方法之前,这一切似乎都运行良好:

System.out.println(response1.getStatusCode());

我找不到符号错误,我似乎无法访问大多数CloseableHttpResponse方法。这是我的代码:

import java.io.IOException;
import java.util.List;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.CloseableHttpResponse;

public class ToDoManager {

    public List<TODO> getAll() throws IOException {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet("http://localhost:8080/assignment3_server_13209572/todos");
        CloseableHttpResponse response1 = httpclient.execute(httpGet);

        try {
            System.out.println(response1.getStatusCode());
        } finally {
            response1.close();
        }
    }

我不确定自己错过了什么,我们将不胜感激。

干杯,

迦勒。

1 个答案:

答案 0 :(得分:0)

我明白了,事实证明httpclient需要httpcoreApache commons-logging作为依赖关系。我的错误。