簡體   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