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);

?>

.medrectangle-3-multi-157{border:none!important;display:block!important;float:none;line-height:0;margin-bottom:15px!important;margin-left:0!important;margin-right:0!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:250px;padding:0;text-align:center!important}

i hope it can help you…

Leave a Comment