How do I call rest web services with untrusted SSL certificates?

Source: Internet
Author: User
Tags ssl certificate

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 );

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.