简体   繁体   中英

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. It all seemed to be working well until I tried to use a CloseableHttpResponse method:

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

I get a cannot find symbol error and I can't seem to access most of the CloseableHttpResponse methods. 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. My mistake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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