Java accesses extranet HTTPS via proxy

Source: Internet
Author: User

Accessing extranet HTTPS via proxy
public class Test99999 extends thread{

public static void Main (string[] args) throws Exception {
Set up agents
String proxy = "openproxy.huawei.com";
int port = 8080;
System.setproperty ("Proxytype", "4");
System.setproperty ("ProxyPort", integer.tostring (port));
System.setproperty ("ProxyHost", proxy);
System.setproperty ("Proxyset", "true");

String url= "https://www.smics.com/";
Sslcontext sc = sslcontext.getinstance ("SSL");

Specify Trust HTTPS
Sc.init (NULL, New Trustmanager[]{new Trustanytrustmanager ()}, New Java.security.SecureRandom ());
URL console = new URL (URL);
Httpsurlconnection conn = (httpsurlconnection) console.openconnection ();
Conn.setsslsocketfactory (Sc.getsocketfactory ());
Conn.sethostnameverifier (New Trustanyhostnameverifier ());
Conn.connect ();
SYSTEM.OUT.PRINTLN ("Return Result:" +conn.getresponsemessage ());

InputStream is = Conn.getinputstream ();
BufferedReader reader = new BufferedReader (new InputStreamReader (IS));
String curline= "";
while ((CurLine = Reader.readline ())!= null) {
System.out.println (CurLine);
}
Is.close ();
}





private static class Trustanytrustmanager implements X509trustmanager {

public void checkclienttrusted (x509certificate[] chain, String authtype) throws Certificateexception {
}
public void checkservertrusted (x509certificate[] chain, String authtype) throws Certificateexception {
}

Public x509certificate[] Getacceptedissuers () {
return new x509certificate[]{};
}
}

private static class Trustanyhostnameverifier implements Hostnameverifier {
public boolean verify (String hostname, sslsession session) {
return true;
}
}

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.