php 使用curl通过post方式提交json数据




$arrayData = array("name" => "Hagrid", "age" => "36");
$sendJsonData = json_encode($arrayData);
$ch = curl_init('http://127.0.0.1/jietu/test.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $sendJsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
		'Content-Type: application/json',
		'Content-Length: ' . strlen($sendJsonData))
);
var_dump(curl_exec($ch));

你可能感兴趣的:(json,PHP,curl)