user1786822
user1786822

Reputation: 107

Apache HttpClient TLS SSL Example

I am trying to figure out how to log into a webpage using the apache HttpClient. The page is using ssl TLSv1 handshake protocal. And I have username and password for access credentials. I have been reading a bunch of stuff online but I am missing something. Could someone with experience with possibly break down exactly what I need to configure the client to do. I have read that an SSL socket must be setup and I have gotten close to getting it configured correctly but I was getting a SSLv2 handshake protocol.

Also I am not sure if this handshake is failing. I could just simply be not retaining the session information between calls properly. So any help on that would also be appreciated.

    <form name="loginuserform" method="post" action="https://www.site.com/login" id="login_form">
    <div id="loginFields">
        <div class="left_input" id="email_input">
            <input id="emailInput" type="text" name="email" tabindex="1" value="">
        </div>
        <div class="left_input" id="password_input">
            <span class="labelStyle">Password</span>
            <input type="password" name="password" tabindex="2">
        </div>
        <div class="left_input">
            <input type="submit" class="primaryActionButton" value="Sign In" tabindex="3">
        </div>
    </div>

</form>

Could you explain more on how we I could respond to this form.

Upvotes: 0

Views: 6984

Answers (1)

Drona
Drona

Reputation: 7234

Its on the HttpClient site. Its prety simple. You need to provide your SSL socket factory and set the configuration required for the SSL factory like - keystore path and access pwd etc through the system properties. For using the socket factory, check below.

Protocol myhttps = new Protocol("https", new MySSLSocketFactory(), 443);
HttpClient httpclient = new HttpClient();
httpclient.getHostConfiguration().setHost("www.whatever.com", 443, myhttps);
GetMethod httpget = new GetMethod("/");
try {
  httpclient.executeMethod(httpget);
  System.out.println(httpget.getStatusLine());
} finally {
  httpget.releaseConnection();
}

Upvotes: 1

Related Questions