HTTPS directly with the server through the Sslsocket connection is feasible
Import Java.io.InputStream;
Import Java.io.OutputStream;
Import Java.security.SecureRandom;
Import Javax.net.ssl.SSLContext;
Import Javax.net.ssl.SSLSocket;
Import Javax.net.ssl.SSLSocketFactory;
Import Javax.net.ssl.TrustManager;
Import Javax.net.ssl.X509TrustManager;
public class Ssl {
public static void SslSocket2 () throws Exception {
Sslcontext context = sslcontext.getinstance ("SSL");
Initialization
Trustmanager[] TM = {new X509trustmanager () {
Public java.security.cert.x509certificate[] Getacceptedissuers () {
return null;
}
public void checkclienttrusted (java.security.cert.x509certificate[] certs, String authtype) {
}
public void checkservertrusted (java.security.cert.x509certificate[] certs, String authtype) {
}
} };
Context.init (NULL, TM, New SecureRandom ());
Sslsocketfactory factory = Context.getsocketfactory ();
Sslsocket s = (sslsocket) factory.createsocket ("mail.163.com", 443);
System.out.println (S.getenabledprotocols ());
System.out.println (S.getenablesessioncreation ());
System.out.println (S.getuseclientmode ());
System.out.println (S.gethandshakesession (). toString ());
System.out.println (S.getinetaddress ());
System.out.println (S.getsession (). toString ());
System.out.println ("OK");
S.starthandshake ();
OutputStream output = S.getoutputstream ();
InputStream input = S.getinputstream ();
Output.write ("POST https://mail.163.com/entry/cgi/ntesdoor?df=mail163_letter&from=web&funcid=loginone &iframe=1&language=-1&passtype=1&product=mail163&net=t&style=-1&race=1139_1154_ 1123_bj&[email protected] http/1.1 "
+ "\r\naccept:application/x-ms-application, Image/jpeg, Application/xaml+xml, Image/gif, Image/pjpeg, application/ X-MS-XBAP, */* "
+ "\r\nuser-agent:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; trident/4.0; SLCC2;. NET CLR 2.0.50727;. NET CLR 3.5.30729;. NET CLR 3.0.30729;. net4.0c;. NET4.0E) "
+ "\r\ncontent-type:application/x-www-form-urlencoded"
+ "\r\naccept-encoding:gzip, deflate" + "\r\nhost:mail.163.com"
+ "\r\ncontent-length:106" + "\r\nconnection:keep-alive"
+ "\r\ncache-control:no-cache" + "\r\nreferer:http://mail.163.com/"
+ "\R\NACCEPT-LANGUAGE:ZH-CN" + "\ r \ n"
+ "\r\nsavelogin=0&url2=http%3a%2f%2fmail.163.com%2ferrorpage%2ferror163.htm&username=xj-07& password=123456 "). GetBytes ());
System.out.println ("Sent:alert");
Output.flush ();
byte[] buf = new byte[1024];
int len = Input.read (BUF);
System.out.println ("Received:" + new String (buf, 0, Len));
}
public static void Main (string[] args) throws Exception {
SslSocket2 ();
}
}
The same way will
Sslsocket s = (sslsocket) factory.createsocket ("mail.163.com", 443);
Instead of acting, it's not good to make
Sslsocket s = (sslsocket) factory.createsocket ("127.0.0.1", 8080);
There was a problem with the SSL handshake between the client and the proxy server, with further analysis
Https Socket Proxy