gpt4 book ai didi

java - 使用 jetty Http 客户端发送 Https 请求中的 NullPointerException

转载 作者:搜寻专家 更新时间:2023-10-31 20:33:42 24 4
gpt4 key购买 nike

我正在使用 Jetty HTTP 客户端 (v9.2.5) 发送 HTTP 请求它适用于 HTTP 请求 {Post,Get,...}但是当我发送 HTTPS 请求后我看到了这个

java.util.concurrent.ExecutionException: java.lang.NullPointerException
at org.eclipse.jetty.client.util.FutureResponseListener.getResult(FutureResponseListener.java:118)
at org.eclipse.jetty.client.util.FutureResponseListener.get(FutureResponseListener.java:101)
at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:642)

我的职能是

private Object sendHttpPOSTRequest(String url, List<Header> headers,
String content, HttpMethod method) {
try {
HttpClient client = new HttpClient();
client.setMaxConnectionsPerDestination(16);
client.setAddressResolutionTimeout(5000);
client.setConnectTimeout(5000);
client.setMaxRedirects(3);
client.setFollowRedirects(true);
client.setExecutor(_executor);
client.start();
Request req = client.POST(url).content(
new StringContentProvider(content));
if (headers != null)
req = setHeaders(req, headers);
req.header(HttpHeader.CONTENT_TYPE, "application/json");

return req.send();

} catch (Exception e) {
e.printStackTrace();
return "Failed";
}

}

怎么了?

最佳答案

对于 HTTPS,您必须像下面这样使用 httpclient 初始化:

// Instantiate and configure the SslContextFactory
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();

// Instantiate HttpClient with the SslContextFactory
HttpClient httpClient = new HttpClient(sslContextFactory);

// Configure HttpClient, for example:
httpClient.setFollowRedirects(false);

// Start HttpClient
httpClient.start();

关于java - 使用 jetty Http 客户端发送 Https 请求中的 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30052169/

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