【发布时间】:2011-11-03 11:38:09
【问题描述】:
我已经努力解决这个问题,但我无法解决。我正在尝试使用来自 apache 的 httpClient 4.1.2。作为我从示例开始的逻辑,问题是我遇到了一些我不理解的奇怪错误。这是交易:
package ClientWithResponseHandler;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
public class Main {
public final static void main(String[] args) throws Exception {
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet("http://www.google.com/");
System.out.println("executing request " + httpget.getURI());
// Create a response handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = **httpclient.execute(httpget, responseHandler);**
System.out.println("----------------------------------------");
System.out.println(responseBody);
System.out.println("----------------------------------------");
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
}
错误在于“httpclient.execute(httpget, responseHandler);” IT 说它找不到方法 execute(HttpGet,ResponseHandler) 这个问题不应该是例子吗?我究竟做错了什么?! :S
【问题讨论】:
标签: httpclient execute http-get