PHP Curl Request with Certificate (cert pem file option) Example
Hi,
This tutorial shows you php curl request with certificate. if you have question about php curl request with pem certificate then i will give simple example with solution. Here you will learn php curl request pass pem file. you will learn how to send a curl request with pem certificate in php. follow bellow step for php send curl request with pem file certificate.
In this example i will give you example of how to send curl request with pem file certificate authentication request. you can pass pem file certificate as like bellow:
curl_setopt($ch, CURLOPT_SSLCERT, "mycert.pem");
curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM");
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.pem");
curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM");
$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
- Angular Material Autocomplete with API Example
- Laravel Sanctum SPA API Authentication Example
- Laravel 8 Sanctum API Authentication Tutorial
- Laravel 8 REST API with Passport Authentication Tutorial
- Codeigniter Curl Post Request with Parameters Example
- PHP CURL Post Request with Parameters Example
- Laravel Block/Whitelist IP Address Tutorial
- Laravel CURL Request Example using Ixudra/curl
- Laravel Mailchimp API Integration Example
- PHP Download File from URL using CURL Request Example
- How to Get Product using Rakuten Marketing API in PHP?