• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To get context of a secure site

Snehanshu Chatterjee
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using this code to get the context (or html code) of any website
via a proxy server installed

public class MyHttpClient {

private static String url = "https://java.sun.com/";
static String proxy_host = "proxyhostname";
static int proxy_port = proxyport;

public static void main(String[] args) throws MalformedURLException {

HttpClient client = new HttpClient();
PostMethod httpget = new PostMethod(url);
client.getHostConfiguration().setProxy(proxy_host, proxy_port);
System.out.println("$$$$$$$$ Before supplying credentials $$$$$$$$");
Credentials creds = new UsernamePasswordCredentials("proxyusername", "proxypassword");
//use a null realm
client.getState().setProxyCredentials(null, proxy_host, creds);
//enable preemptive authentication
System.out.println("$$$$$$$$ After proxy validation $$$$$$$$");

Logger logger = Logger.getLogger(MyHttpClient.class);
logger.info("Entering application.");
DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler();
System.out.println("Look up");

try {
int statusCode = client.executeMethod(httpget);

if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + httpget.getStatusLine());
byte[] responseBody = httpget.getResponseBody();

//System.out.println(new String(responseBody));
} catch (IOException e) {
System.err.println("Failed to download file.");
} finally {

But problem lies when I want to see the context of a website which needs the client to accept a certificate.
Then the error shows:::

"This error occurs when the resource you are attempting to access requires your browser to have a Secure Sockets Layer (SSL) client certificate that the server recognizes"

I have already install the required certificate in the browser...
I have a client side certificate and a server side certificate

suggest me any code to solve this problem, so that I can get the context of a secure site also..
Thanks in advance..........
Ulf Dittmer
Posts: 42968
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

If you run a Java client it won't do any good to have the certificate installed in the browser. It also needs to be installed where the JDK can find it. Here's an article that talks about that, or consult the keytool documentation that comes with the JDK.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic