2017-03-18 53 views
1

我使用HttpClient和我用httpCore.jar和我依然面临着一个异常阿帕奇HttpClientBuilder产生的ClassNotFoundException:org.apache.http.config.Lookup

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

该类可在httpcore 4.4.4 .jar,请检查jar的版本,我试过你的代码,它不会抛出任何没有发现异常的类。如果有jar,那么请确保jar被添加到应用程序类路径中。