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

vu8f3i0k  于 2023-08-01  发布在  Java
关注(0)|答案(3)|浏览(104)

我正在尝试构建一个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的新手。
谢谢你的帮助。

tpgth1q7

tpgth1q71#

尝试使用“httpcore - 4.1.3”(与您的httpclient jar版本相同)jar文件。您将能够成功导入org.apache.http.ssl.SSLContexts

hgqdbh6s

hgqdbh6s2#

即使不导入org.apache.http.ssl.SSLContexts,也可能出现此错误
尝试从maven存储库导入pom.xml文件中的httpcore包。
也检查你有httpclient包。

  • httpcore和httpclient不需要版本相同 *
kjthegm6

kjthegm63#

你有没有可能用
org.apache.httpcomponents httpclient 4.5.2
然后是import org.apache.http.conn.ssl.SSLContexts

相关问题