Send POST Request using PHP

cURL extension

  1. Enable extension in php.ini file:
extension=curl
  1. Send POST request:
<?php

$data = 'name=John&age=20';

$ch = curl_init('https://httpbin.org/post');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$content = curl_exec($ch);
curl_close($ch);

echo $content;

Leave a Comment

Cancel reply

Your email address will not be published.