相关文章推荐
玩篮球的西装  ·  HttpClientJsonExtensio ...·  昨天    · 
英俊的铁板烧  ·  EXCEL ...·  1 年前    · 
重情义的鸵鸟  ·  MacOS10.14 ...·  1 年前    · 
含蓄的火柴  ·  调研linux库alsa - 简书·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am using Jetty HTTP Client (v9.2.5) To Send HTTP Request It is Work Fine For HTTP Request {Post,Get,...} But When I send HTTPS Request Post I See This

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)

My Function Is

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";

Whats Wrong?

Define at the Top of class private ExecutorService _executor = Executors.newCachedThreadPool(); – Ali Kianinejad May 5, 2015 at 11:57

For HTTPS you have to use the httpclient initialization like the following way:

// 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();

You should use (see https://www.eclipse.org/jetty/documentation/current/http-client.html):

// 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();
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.