我在http://hc.apache.org/downloads.cgi上下载了一个HttpClient 4.0-beta1我把httpClient class已经加到程序里,
我用最简单的例子(httpClient自带的例子),测试了下package com.fuou;import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* This example demonstrates the use of the {@link ResponseHandler} to simplify
* the process of processing the HTTP response and releasing associated resources.
*/
public class ClientWithResponseHandler { public final static void main(String[] args) throws Exception {
HttpClient httpclient = new DefaultHttpClient();
//HttpResponse response = httpclient.execute(httpget); // 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(responseBody);
System.out.println("----------------------------------------");
}
}
我已改成上面的程序,但还报 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/params/HttpParams错误,
我在httpClient里也确实 没找到Httpparams类文件,这是怎么回事!要到哪去找这个类,还是我下错了?
我用最简单的例子(httpClient自带的例子),测试了下package com.fuou;import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* This example demonstrates the use of the {@link ResponseHandler} to simplify
* the process of processing the HTTP response and releasing associated resources.
*/
public class ClientWithResponseHandler { public final static void main(String[] args) throws Exception {
HttpClient httpclient = new DefaultHttpClient();
//HttpResponse response = httpclient.execute(httpget); // 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(responseBody);
System.out.println("----------------------------------------");
}
}
我已改成上面的程序,但还报 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/params/HttpParams错误,
我在httpClient里也确实 没找到Httpparams类文件,这是怎么回事!要到哪去找这个类,还是我下错了?
Binary 下的4.0-beta1.zip 和 Binary with dependencies 的 4.0-beta1.zip,
然后把里面的Jar包导入项目,就OK了。