PHP POST JSON using cURL

You can use this PHP code snippet to POST JSON using cURL.


									<?php

$data = array(
	"name" => "Wise Man",
	"message" => "Hello, World!"
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/test/test.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$output = curl_exec($ch);
curl_close($ch);
echo $output;

?>
								

coding-ninja

A dream without a plan is just a wish.

Comments (0)

No Comments Yet.