【问题标题】:Apache HttpClientBuilder produces ClassNotFoundException: org.apache.http.config.LookupApache HttpClientBuilder 产生 ClassNotFoundException: org.apache.http.config.Lookup
【发布时间】:2017-08-11 01:33:04
【问题描述】:

我正在使用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);
        }
    }
}

【问题讨论】:

    标签: java apache-httpclient-4.x


    【解决方案1】:

    该类在 httpcore 4.4.4.jar 中可用,请检查 jar 的版本,我尝试了您的代码,它没有抛出任何类未找到异常。如果 jar 存在,请确保将 jar 添加到应用程序类路径中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多