gpt4 book ai didi

java - Apache HttpClientBuilder 产生 ClassNotFoundException : org. apache.http.config.Lookup

转载 作者:太空宇宙 更新时间:2023-11-04 11:40:16 26 4
gpt4 key购买 nike

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

最佳答案

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

关于java - Apache HttpClientBuilder 产生 ClassNotFoundException : org. apache.http.config.Lookup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42870904/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com