How To Send PHP Curl POST Request With Parameters Using Json Example
Sep 22, 2021
Hi guys,
Today i will explained how to send PHP Curl POST Request With Parameters Using Json Example. This example is so easy to use in php.
This Example to i am explained to how to send curl post request in json using php to explained in this example. So let's start to the example and follow to the my all step.
Example :
<?php
$url = 'https://api.Nicesnippets.com/api/users';
$data = array("first_name" => "First name","last_name" => "last name","email"=>"[email protected]");
$postdata = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
curl_close($ch);
print_r ($result);
?>
Finally resize to the your file in your folder.
So, finally we are done with our code we can get below output.
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example