php curl post raw json参数

php curl post raw json参数

"sdf",
    "location"=>"sdf",
    "imgs"=>[
        "sdfsd",
		"sdfsd"
        ]
	];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,            "http://test.com/dump.php" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST,           1 );
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($params));// 必须为字符串
curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: text/plain'));// 必须声明请求头
$return = curl_exec($ch);

var_dump($return);
?>

主要两个地方:

curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($params));
curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: text/plain'));



接收参数dump.php

你可能感兴趣的:(PHP深入实践)