rohitkadam19 rohitkadam19 - 1 year ago 392
Java Question

How to make HTTPS GET call with certificate in Rest-Assured java

How can I make a GET call using Rest-Assured in java to a endpoint which requires certificate. I have certificate as

format. In PEM file there is certificate and private key.

Answer Source

Got it working with following code -

KeyStore keyStore = null;
SSLConfig config = null;

try {
        keyStore = KeyStore.getInstance("PKCS12");
                new FileInputStream("certs/client_cert_and_private.p12"),

    } catch (Exception ex) {
        System.out.println("Error while loading keystore >>>>>>>>>");

    if (keyStore != null) {

        org.apache.http.conn.ssl.SSLSocketFactory clientAuthFactory = new org.apache.http.conn.ssl.SSLSocketFactory(keyStore, password);

        // set the config in rest assured
        config = new SSLConfig().with().sslSocketFactory(clientAuthFactory).and().allowAllHostnames();

RestAssured.config = RestAssured.config().sslConfig(config);