HTTP 4.3 previous HttpClient httpclient = HttpClient1; Create TrustManager X509trustmanager XTM = new X509trustmanager () {public void checkclienttrusted (x509certificate [] chain, String authtype) throws certificateexception {} public void checkservertrusted (X50 9certificate[] chain, String authtype) throws certificateexception {} public X509Certificate
[] Getacceptedissuers () {return new x509certificate[] {};
}
};
try {sslcontext ctx = sslcontext.getinstance ("SSL");
Use TrustManager to initialize the context, TrustManager is only used by SSL sockets Ctx.init (NULL, new trustmanager[] {XTM}, NULL);
Sslsocketfactory SF = new Sslsocketfactory (CTX, sslsocketfactory.allow_all_hostname_verifier);
Scheme sch = new scheme ("https", 443, SF);
Httpclient.getconnectionmanager (). Getschemeregistry (). Register (Sch); Create HttpPost HttpGet HttpPost =New HttpGet (URL);
Httppost.setheader ("Content-type", contexttype);
Perform POST requests HttpResponse response = Httpclient.execute (HttpPost);
Get response entity httpentity entity = response.getentity ();
BS = Ioutils.tobytearray (Entity.getcontent ());
if (null!= entity) {Entityutils.consume (entity);//Consume response content} return BS;
catch (Exception e) {e.printstacktrace ();
Finally {//close connection, free resources//Httpclient.getconnectionmanager (). Shutdown ();
} return BS;
} ========================================================================================================== after 4.3
Sslcontext Sslcontext; try { Sslcontext = new Sslcontextbuilder (). loadtrustmaterial (NULL, New TrustStrategy () { //Trust all public boolean istrusted (x509certificate[] chain, String authtype) throws Certificateexception {
return true;
} }). Build (); sslconnectionsocketfactory SSLSF = new SslconneCtionsocketfactory ( Sslcontext,
Sslconnectionsocketfactory.allow_all_hostname_verifier); httpclient = Httpclients.custom ()
setsslsocketfactory (SSLSF). build ();
HttpPost httppost = new HttpPost (HTTPADDR2); //httpclient Construction Completion Construction request Parameters
list<namevaluepair> formparams = new arraylist<namevaluepair> ();
Formparams.add (New Basicnamevaluepair ("Sender_code", spid));
Formparams.add (New Basicnamevaluepair ("Trx_content", Base64str)); Formparams.add (New Basicnamevaluepair ("SIGNATURE", Md5str));
urlencodedformentity uefentity;
uefentity = new urlencodedformentity (formparams);
httppost.setentity (uefentity);
closeablehttpresponse response = Httpclient.execute (HttpPost);
httpentity entity = response.getentity ();