我正在使用 apache http commons 4。我在 netbeans 的类路径中添加了 httpcore-4.0.1.jar 和 httpclient-4.0.1.jar。我收到错误:
java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient
我的代码如下。请帮忙。
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;
public class HttpClientManager {
public HttpClient httpclient;
public HttpClientManager() {
this.init();
}
public void init() {
try {
httpclient = new DefaultHttpClient();
} catch (Exception e) {
e.printStackTrace();
}
}
public void getCourseList() {
String url = "http://exnet.in.th/api.php?username=demoinst&ha=2b62560&type=instructor";
HttpGet httpget = new HttpGet(url);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
String responseBody = httpclient.execute(httpget, responseHandler);
System.out.println(responseBody);
} catch (Exception e) {
}
}
}