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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Http Curl Delete Request Example
- Laravel Http Curl Get Request Example
- PHP Curl Request with Username and Password Example
- PHP Curl Request With Bearer Token Authorization Header Example
- PHP Curl PUT Request Example Code
- PHP Curl Delete Request Example Code
- PHP Curl POST Request with Headers Example
- PHP Curl Get Request with Parameters Example
- PHP Curl Request with Certificate (cert pem file option) Example
- Codeigniter Curl Post Request with Parameters Example
- PHP CURL Post Request with Parameters Example