Curl POST method

Curl POST method

Curl POST method


 $api_url = 'domainname.com/api/demo';

 $headers = array(
 'Authorization: Bearer Token',
 'api-key: 'api_key',
 );

 $params = array(
 'name' => $request->name,
 'email' => $request->email,
 'phone' => $request->phone,
 'subject' => $request->subject,
 'message' => $request->message,
 );

 $curl = curl_init();
 
 curl_setopt_array($curl, array(
 CURLOPT_URL => $api_url,
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_ENCODING => '',
 CURLOPT_MAXREDIRS => 10,
 CURLOPT_TIMEOUT => 0,
 CURLOPT_FOLLOWLOCATION => true,
 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
 CURLOPT_CUSTOMREQUEST => 'POST',
 CURLOPT_POSTFIELDS => json_encode($params),
 CURLOPT_HTTPHEADER => $headers,
 ));
 
 $result = curl_exec($curl);
 $response = json_decode($result, true);

0 Comment's

Add Comment

Register to Reply

About Author

Looking for a reliable and skilled web developer? I'm Bhawesh Bhaskar, a Senior Full Stack Software Developer with proven expertise in both front-end and back-end development. I provide professional website design, custom web application development, and robust PHP solutions using Laravel, CodeIgniter, and Core PHP. I help businesses create modern, responsive, and high-performance websites that drive results. Whether you're starting from scratch or need to upgrade your existing site, I deliver solutions tailored to your goals.
💼 Let’s build something great together — contact me today for a free consultation!