我目前正在http client
中构建一个非常简单的Netbeans 8.2
,并希望使用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();
}
}
我不确定自己错过了什么,我们将不胜感激。
干杯,
迦勒。
答案 0 :(得分:0)
我明白了,事实证明httpclient
需要httpcore
和Apache commons-logging
作为依赖关系。我的错误。