Dear All,
I want to write a
servlet client which access a https url and pass parameters and then accept the response.
To use https i have added following lines:
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
HttpsURLConnection connection =(HttpsURLConnection) url.openConnection();
..
..
connection.setRequestProperty("Authorization",
"Basic " +
Base64Encoder.encode(USERNAME + ":" + USERPASSWORD));
But i got following error message:
java.io.IOException: HTTPS hostname wrong: should be <abc>, but cert says <xyz>
I used the following code to reslove this problem:
connection.setHostnameVerifier(
new HostnameVerifier()
{
public boolean verify(
String urlHost, String certHost )
{
if( !urlHost.equals( certHost ) )
{
System.out.println( " Ignoring certificate <" + certHost +
"> does not match host <" + urlHost + "> " +
"continuing anyway" );
}
Is there any other way to solve this?
What do i need to do to set following :
System.setProperty("javax.net.ssl.keyStore"," ??");
System.setProperty("javax.net.ssl.keyStoreType","??");
System.setProperty("javax.net.ssl.keyStorePassword","??");
System.setProperty("javax.net.ssl.trustStore","??");
System.setProperty("javax.net.ssl.trustStoreType","??");
System.setProperty("javax.net.ssl.trustStorePassword","??");
Any help or guideline is highly appreciated.I don't have any information about the server side . All i have is https url and username and password.
Thanks,
peterabc