Author: chszs, reprinted with note.
Author blog homepage: http://blog.csdn.net/chszs
In our development environmentProgramWe have configured a self-Signed SSL certificate. Obviously, we will not spend the certificate money on the development server. Therefore, we are faced with the issue of "how to call rest web services with untrusted SSL certificates.
I use the Jersey rest client to call the rest web service,CodeThe diagram is as follows:
The author chszs should be noted for reprinting. Blog homepage: http://blog.csdn.net/chszs
Trustmanager [] trustallcerts = new trustmanager [] {New x509trustmanager () {public parts [] getacceptedissuers () {return NULL;} public void checkclienttrusted (parts [] certs, string authtype) {} public void checkservertrusted (x509certificate [] certs, string authtype) {}}; sslcontext context = sslcontext. getinstance ("TLS"); context. init (null, trustallcerts, new securerandom (); httpsurlconnection. setdefaultsslsocketfactory (context. getsocketfactory (); clientconfig Config = new defaultclientconfig (); config. getproperties (). put (httpsproperties. property_https_properties, new httpsproperties (New hostnameverifier () {@ override public Boolean verify (string S, sslsession) {return true ;}, context); Client client = client. create (config); client. setfollowredirects (true); webresource resource = client. resource ("https: // myserver/myws"); resource. accept (mediatype. application_json_type); string result = resource. post (string. class );