Call the javax.net. SSL package to retrieve the HTTPS page content.

Source: Internet
Author: User
If a page is https, you can obtain its content and HTTPS authentication information:

Import java.net. malformedurlexception;

Import java.net. url;

Import java. Security. cert. Certificate;

Import java. Io .*;

Import javax.net. SSL. httpsurlconnection;

Import javax.net. SSL. sslpeerunverifiedexception;

Public class httpsclient {

/**

* @ Param ARGs

*/

Public static void main (string [] ARGs)

{

New httpsclient (). testit ();

}

Private void testit (){

String https_url = "https://www.aegpromotion.com/JackyGWIC2011/ SC /terms.asp ";

URL;

Try {

Url = new URL (https_url );

Httpsurlconnection con = (httpsurlconnection) URL. openconnection ();

// Dumpl all Cert info

Print_https_cert (CON );

// Dump all the content

Print_content (CON );

} Catch (malformedurlexception e ){

E. printstacktrace ();

} Catch (ioexception e ){

E. printstacktrace ();

}

}

Private void print_https_cert (httpsurlconnection con ){

If (con! = NULL ){

Try {

System. Out. println ("response code:" + con. getresponsecode ());

System. Out. println ("cipher suite:" + con. getciphersuite ());

System. Out. println ("\ n ");

Certificate [] certs = con. getservercertificates ();

For (certificate Cert: CERTS ){

System. Out. println ("Cert Type:" + cert. GetType ());

System. Out. println ("Cert hash code:" + cert. hashcode ());

System. Out. println ("Cert public key algorithm:" + cert. getpublickey (). getalgorithm ());

System. Out. println ("Cert public key format:" + cert. getpublickey (). getformat ());

System. Out. println ("\ n ");

}

} Catch (sslpeerunverifiedexception e ){

E. printstacktrace ();

} Catch (ioexception e ){

E. printstacktrace ();

}

}

}

Private void print_content (httpsurlconnection con ){

If (con! = NULL ){

Try {

System. Out. println ("****** content of the URL ********");

Bufferedreader BR =

New bufferedreader (

New inputstreamreader (con. getinputstream ()));

String input;

While (input = Br. Readline ())! = NULL ){

System. Out. println (input );

}

BR. Close ();

} Catch (ioexception e ){

E. printstacktrace ();

}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.