Laravel REST API Curl Post Request

Today we will talk about how you can make curl post request in laravel which includes authorization header.

Here you can use inside your controller method or helper or custom class method.

For that you have to pass some parameters like the POST data .

<?php 

$postData = ['email'=>"test@mail.com"];
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL =>  'https://coderuck.com/api/userCheck',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode($postData),
  CURLOPT_HTTPHEADER => array(
    "Authorization:Bearer HJJG55588GTGGnnjuhg",
    "Cache-Control: no-cache",
    "Content-Type: application/json"
  ),
));
$response = curl_exec($curl);
$finalResponse = json_decode($response,true);
$err = curl_error($curl);
curl_close($curl);
return $finalResponse;

?>

Leave a reply

your email address will not be published. required fields are marked *

Name *
Email *
Website