• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

having trouble with reading source of secure page

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Right! We're on it! Let's get to work tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic