繁体   English   中英

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

[英]Apache httpcomponents-client - CloseableHttpResponse methods not working

我目前正在Netbeans 8.2构建一个非常简单的http client ,并希望使用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();
        }
    }

我不确定我缺少什么,任何帮助将不胜感激。

干杯,

迦勒。

我知道了,事实证明httpclient需要httpcoreApache commons-logging作为依赖项。 我的错。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM