PHP Curl Request with P12 Certificate Example
Today our leading topic is php curl request with p12 certificate. we will help you to give example of php curl request with p12 certificate. This article goes in detailed on php curl request pass p12 file. we will help you to give example of how to send a curl request with p12 certificate in php. Alright, letβs dive into the steps.
In this example i will give you example of how to send curl request with p12 file certificate authentication request. you can pass p12 file certificate as like bellow:
curl_setopt($ch, CURLOPT_SSLCERT, "mycert.p12");
curl_setopt($ch, CURLOPT_SSLCERTTYPE, "p12");
Example:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_cert");
curl_setopt($ch, CURLOPT_SSLCERT, "mycert.p12");
curl_setopt($ch, CURLOPT_SSLCERTTYPE, "p12");
$headers = [];
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
return false;
}
curl_close($ch);
$result = json_decode($result);
print_r($result);
?>
i hope it can help you...