How to call Https REST Api from Azure Function written in Java

Bhushan Patil 0 Reputation points
2024-04-25T10:37:17.3866667+00:00

Hello I created an azure function with java, i want to call rest apis with https and i am facing this issue :
SSLHandshakeException@76 "javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

this is my function code which i use to call api it is working fine with http urls but throwing above error for https

        OkHttpClient client = new OkHttpClient().newBuilder()
                    .build();
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(apiBody, mediaType);
        Request request = new Request.Builder()
                .url(apiUrl)
                .method("POST", body)
                .addHeader("Content-Type", "application/json")
                .build();
        client.newCall(request).execute();
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,300 questions
{count} votes