Cannot connect to an https server
Hi,
I searched far and wide in the forum for a resolution to my problem but did not find any solution. Hence posting the problem here. Please help.
I need to make a call to an https server using a POST request from a SunOS 5.8 machine. Some parameters are to be passed to it. The server would return me back an xml that I need to process. But on execution the class just hangs and on a ^C , I get
a SocketException : Operation already in progress
Is it because I need to do any configurations at my end so as to make the call go through ? Or is there any thing wrong in my code ?
Thanks in advance. I am really looking forward to any help in this regard ssince its of a very high importance that I get it working
The code am trying out is here
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.StringTokenizer;
import javax.net.ssl.HttpsURLConnection;
public class clsInvokeOgone_backup{
private static final String BASE_URL="https://secure.xxxxx.com/ncol/test/orderdirect.asp";
public static void main(String[] args) {
String inputData="orderID=9999&PSPID=TESTDPR&PSWD=9999&amount=500¤cy=EUR&COM=blabla&CN=SG&BRAND=VISA&CRNO=1234567890123456&ED=1
2/07&email=abcd@xyz.com";
try {
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("java.protocol.handler.pkgs","javax.net.ssl");
String sURL = BASE_URL, sOut = "", line, uri = "";
StringTokenizer tok = new StringTokenizer(sURL);
String protocol = tok.nextToken(":");
String host = tok.nextToken("://");
//String sPostData = postData;
try {
uri += "/" + tok.nextToken("/");
while (tok.hasMoreTokens())
uri += "/" + tok.nextToken("/");
}
catch(Exception nsee) {
uri += "/";
}
System.out.println("protocol -"+protocol+"host = " + host + "uri = " + uri);
URL url = new URL(protocol, host, uri);
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
// inform the connection that we will send output and accept input
con.setDoInput(true);
con.setDoOutput(true);
// Don't use a cached version of URL connection.
con.setUseCaches (false);
con.setDefaultUseCaches (false);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
System.out.println("just before connect");
//con.connect();
System.out.println("onnect");
// define a new PrintWriter on the output stream
PrintWriter outWriter = new PrintWriter(con.getOutputStream());
outWriter.print("?"+inputData);
outWriter.close();
System.out.println("onnect");
DataInputStream input = new DataInputStream (con.getInputStream ());
String str;
while (null != ((str = input.readLine())))
{
System.out.println (str);
}
input.close ();
} catch(IOException ioe)
{
ioe.printStackTrace();
}
}
}

