解析PHP 使用curl提交json格式数据
程序员文章站
2022-06-20 19:35:35
复制代码 代码如下:$data = array("name" => "hagrid", "age" => "36");$data_string = json_e...
复制代码 代码如下:
$data = array("name" => "hagrid", "age" => "36");
$data_string = json_encode($data);
$ch = curl_init('http://api.local/rest/users');
curl_setopt($ch, curlopt_customrequest, "post");
curl_setopt($ch, curlopt_postfields,$data_string);
curl_setopt($ch, curlopt_returntransfer,true);
curl_setopt($ch, curlopt_httpheader, array(
'content-type: application/json',
'content-length: ' . strlen($data_string))
);
$result = curl_exec($ch);
上一篇: Linux服务器选择什么版本好
下一篇: 红酒的保质期有多久?什么是红酒的适饮期?