简体   繁体   English

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

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

I'm currently building a very simple http client in Netbeans 8.2 and want to use the Apache httpcomponents-client 4.5 library. 我目前正在Netbeans 8.2构建一个非常简单的http client ,并希望使用Apache httpcomponents-client 4.5库。 It all seemed to be working well until I tried to use a CloseableHttpResponse method: 在尝试使用CloseableHttpResponse方法之前,一切似乎都运行良好:

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

I get a cannot find symbol error and I can't seem to access most of the CloseableHttpResponse methods. 我收到找不到符号错误,而且似乎无法访问大多数CloseableHttpResponse方法。 Here is my code: 这是我的代码:

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();
        }
    }

I'm not sure what I'm missing and any help would be greatly appreciated. 我不确定我缺少什么,任何帮助将不胜感激。

Cheers, 干杯,

Caleb. 迦勒。

I figured it out, it turns out that httpclient requires httpcore and and Apache commons-logging as dependencies. 我知道了,事实证明httpclient需要httpcoreApache commons-logging作为依赖项。 My mistake. 我的错。

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

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