[英]How request CONNECT with Apache HttpComponents Client
[英]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
需要httpcore
和Apache commons-logging
作為依賴項。 我的錯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.