The HttpGet class represents the HTTPGET request which retrieves the information of the given server using a URI. Create a HTTP GET request by instantiating this class. The constructor of this class accepts a String value representing the URI. HttpGet httpget = new HttpGet ('http://www.tutorialspoint.com/'). From what I know, you can't do this with the default HttpGet class that comes with the Apache library. However, you can subclass the HttpEntityEnclosingRequestBase entity and set the method to GET. I haven't tested this, but I think the following example might be what you're looking for.
Customizing SSL in HttpClient
The default behaviour of HttpClient is suitable for most uses, however there are some aspects which you may want to configure. The most common requirements for customizing SSL are:
- Ability to accept self-signed or untrusted SSL certificates. This is highlighted by an
SSLExceptionwith the message Unrecognized SSL handshake (or similar) being thrown when a connection attempt is made.
- You want to use a third party SSL library instead of Sun's default implementation.
Implementation of a custom protocol involves the following steps:
Apache Httpget Download
Apache Httpget Slower Than Other Clients
Provide a custom socket factory that implements org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory interface. The socket factory is responsible for opening a socket to the target server using either the standard or a third party SSL library and performing any required initialization such as performing the connection handshake. Generally the initialization is performed automatically when the socket is created.
Instantiate an object of type org.apache.commons.httpclient.protocol.Protocol. The new instance would be created with a valid URI protocol scheme (https in this case), the custom socket factory (discussed above) and a default port number (typically 443 for https). For example:
The new instance of protocol can then be set as the protocol handler for a HostConfiguration. For example to configure the default host and protocol handler for a HttpClient instance use:
Finally, you can register your custom protocol as the default handler for a specific protocol designator (eg: https) by calling the Protocol.registerProtocol method. You can specify your own protocol designator (such as 'myhttps') if you need to use your custom protocol as well as the default SSL protocol implementation.
Once registered the protocol be used as a 'virtual' scheme inside target URIs.
If you want this protocol to represent the default SSL protocol implementation, simply register it under 'https' designator, which will make the protocol object take place of the existing one