我正在使用HttpClient
而且我使用httpCore.jar
但仍然面临异常
java.lang.ClassNotFoundException: org.apache.http.config.Lookup Error
围绕
HttpClient client = HttpClientBuilder.create().build();
我的完整代码正在关注
package com.rest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
public class Test33 {
/**
* @param args
* @throws IOException
* @throws ClientProtocolException
*/
public static void main(String[] args) throws ClientProtocolException, IOException {
String url = "http://www.google.com/search?q=httpClient";
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
System.out.println("Response Code : "
+ response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
}
}
答案 0 :(得分:0)
这个类在httpcore 4.4.4.jar中可用,请检查jar的版本,我尝试了你的代码,它没有抛出任何类找不到异常。如果jar在那里,那么请确保将jar添加到应用程序类路径。