【发布时间】:2015-08-14 18:19:55
【问题描述】:
我有这个程序:
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
public class ApplicationRESTFul {
public static void main(String[] args) {
String url = "http://www.google.com/search?q=httpClient";
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);
request.addHeader("Accept", "application/json");
}
}
但我从 eclipse 收到了这条消息
the method addHeader (String, String) is undefined for the type HttpGet
我正在使用这个库,正如我在文档中看到的那样,该方法应该存在(org.apache.httpcomponents.httpclient_4.5)
【问题讨论】:
-
对我来说很好......
-
您还有其他导入类名为
HttpGet的类吗? -
试试这个:
org.apache.http.client.methods.HttpGet request = new org.apache.http.client.methods.HttpGet(url); -
我遇到了同样的错误 :-(
标签: java rest apache-httpclient-4.x