Reputation: 41
I'm using HttpClient
and and I use httpCore.jar
and still I'm facing an exception
java.lang.ClassNotFoundException: org.apache.http.config.Lookup Error
around
HttpClient client = HttpClientBuilder.create().build();
My full code is following
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);
}
}
}
Upvotes: 4
Views: 6790
Reputation: 3774
The class is available in httpcore 4.4.4.jar, Please check the version of jar and I tried your code and it doesn't throw any class not found exception. If jar is there then please make sure that jar is added to application classpath.
Upvotes: 2