Java org.apache.http.ssl.SSLContext 未找到

问题描述 投票:0回答:3

我正在尝试构建一个 HttpClient,但无法弄清楚如何解决此 ClassNotFound-Error。我用 maven 和其他几个库安装了“org.apache.httpcomponents:httpclient:4.1.3”,但我还无法工作。

代码:

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.*;
import java.net.URISyntaxException;
import java.util.*;

public class Test {
    public static void main(String[] args) {
        String bearerToken = "BLABLA";
        HttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()).build();
    }
}

对应的错误信息:

Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ssl/SSLContexts
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:977)
    at Twitter.main(Twitter.java:23)
Caused by: java.lang.ClassNotFoundException: org.apache.http.ssl.SSLContexts
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)

我当前安装的 Maven 存储库:

oauth.signpost:signpost-commonshttp4:2.0.0
org.json:json:20200518
org.apache.httpcomponents:httpclient:4.1.3

请注意,我是 Java 和 Intellij-IDE 的新手。

感谢您的帮助。

java httpclient
3个回答
0
投票

尝试使用“httpcore - 4.1.3”(与您的

httpclient
jar 版本相同)jar 文件。您将能够成功导入
org.apache.http.ssl.SSLContexts


-1
投票

你可以使用吗

org.apache.httpcomponents http客户端4.5.2

然后

import org.apache.http.conn.ssl.SSLContexts


-1
投票

即使您没有导入,也可能会出现此错误

org.apache.http.ssl.SSLContexts

尝试从 pom.xml 文件中的 Maven 存储库导入

httpcore
包。

还要检查您是否有

httpclient
包裹。

httpcore 和 httpclient 需要相同版本

© www.soinside.com 2019 - 2024. All rights reserved.