HTTPS using Jersey Client

后端 未结 5 1862
遇见更好的自我
遇见更好的自我 2020-11-28 21:18

How do I send GET requests using the Jersey Client API to a server which runs on the HTTPS protocol. Is there any sample code that I can use ?

5条回答
  •  鱼传尺愫
    2020-11-28 22:22

    Construct your client as such

    HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
    ClientConfig config = new DefaultClientConfig();
    SSLContext ctx = SSLContext.getInstance("SSL");
    ctx.init(null, myTrustManager, null);
    config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostnameVerifier, ctx));
    Client client = Client.create(config);
    

    Ripped from this blog post with more details: http://blogs.oracle.com/enterprisetechtips/entry/consuming_restful_web_services_with

    For information on setting up your certs, see this nicely answered SO question: Using HTTPS with REST in Java

提交回复
热议问题