Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jewelhuq's avatar

How to convert this code Laravel Http Post

        $url = "https://accounts.com/auth/oauth/v2/token";
        $keyFile = dirname(__FILE__) . '/certificates/cert.key';
        $certFile = dirname(__FILE__) . "/certificates/cert.pem";

        $clientCert = $certFile;//file_get_contents($certFile);
        $clientKey = $keyFile;//file_get_contents($keyFile);


        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_SSLKEY, $clientCert);
        curl_setopt($ch, CURLOPT_SSLCERT, $clientKey);

        $headers = array();
        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_SSLCERT, $certFile);
        curl_setopt($ch, CURLOPT_SSLKEY, $clientKey);

        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close($ch);
        $access_token = json_decode($result, true);
        return $access_token["access_token"] ??"";



How to write this curl code with laravel Http:Post method
0 likes
7 replies
Snapey's avatar

please format your question with three backticks ``` on their own line before and after the code blocks

shawnveltman's avatar

There doesn't seem to be any mention of using --cert in the Laravel docs for the Http facade either. So you may well be out of luck.

Please or to participate in this conversation.