| Author |
having trouble with reading source of secure page
|
Aravind Srinivasan
Greenhorn
Joined: Oct 20, 2006
Posts: 1
|
|
Actually Iam trying to connect to the secure url of a servlet from a standalone java code . Iam able to openconnection to the url, but when i try to read the source of that secure page , Iam only able to see the header information, tabs etc but the real contents of the page are not shoing up. i have attached my code. Can anybody suggest me something to fix this issue? import java.net.*; import javax.net.ssl.*; //import java.util.*; //import javax.net.*; import java.io.*; import java.security.Security; import java.security.Permission; //import java.security.*; //import java.security.cert.X509Certificate; public class SecureClientReader { public static void main(String[] args) { try { //Verify if the hostname exixts HostnameVerifier hv = new HostnameVerifier() { public boolean verify(String urlHostName, SSLSession session) { System.out.println("Warning: URL Host: "+urlHostName+" vs. "+session.getPeerHost()); return true; } }; Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol.https"); System.setProperty("https.proxySet","true"); System.setProperty("https.proxyHost", "proxy"); System.setProperty("https.proxyPort", "8080"); HttpsURLConnection.setDefaultHostnameVerifier(hv); System.out.println("connect....."); StringBuffer headerVal = new StringBuffer(80); String userPassword = "loginid" + ":" + "passwd"; String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes()); headerVal.append(encoding); URL url = new URL("https:secure url"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "Basic " + encoding); conn.setRequestMethod("POST"); conn.setRequestProperty("Cache-Control", "no-cache"); //manual basic authentication conn.setDoOutput(true); conn.setDoInput(true); conn.setAllowUserInteraction(false); conn.setInstanceFollowRedirects(false); System.out.println("conn.getContent():"+ conn.getContent().toString()); conn.connect(); // Permission permision = conn.getPermission(); //System.out.println("permission name:"+permision.getName()); // int response = conn.getResponseCode(); // System.out.println( "Response: " + response); // System.out.println(" o/p " +conn.getDoOutput()); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; StringBuffer response = new StringBuffer(); while ((line = in.readLine()) != null) { System.out.println(line); } } catch(Exception e) { e.printStackTrace(); System.out.println(e); //serverSocket.close(); } } // end main } //end SecureClientReader
|
 |
 |
|
|
subject: having trouble with reading source of secure page
|
|
|