php curl post raw json参数
-
-
-
$params = [
-
"title"=>
"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'));
-
-
-
print_r(file_get_contents(
'php://input'));
-
-
?>