jrey
jrey

Reputation: 2183

HTTP Client with https

What is the best way to process HTTP GET Method with SSL using HTTP Components HTTPClient 4 Project? what is the best way to parametrized certification info? properties file? reload method to Daemon Service?

    HttpClient httpClient = new DefaultHttpClient();
    String url = "https://xxx.190.2.45/index.jsp";
    HttpGet get = new HttpGet(url);
    try {
                    //TODO
                    HTTPHelper.addSSLSupport(httpClient);
        HttpResponse response = httpClient.execute(get);

        BasicResponseHandler responseHandler = new BasicResponseHandler();
        String responseString = responseHandler.handleResponse(response);

    } catch (ClientProtocolException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

Upvotes: 0

Views: 205

Answers (1)

Dave G
Dave G

Reputation: 9777

You'll need to enable the SSL support, see the tutorial for more information

I'm under the impression that you're using a self-signed certificate for the server. What you probably should do is look at getting openssl, generate yourself a CA & server certificate. Put the CA certificate (not the private key) in a "trust store" and configure the socket factory.

If you need more detail on how to do this, just comment on this and I'll flesh out some more. I've had great success with simple local projects!

Upvotes: 1

Related Questions