• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic