解析PHP 使用curl提交json格式数据
程序员文章站
2023-11-13 08:52:10
复制代码 代码如下:$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);
上一篇: 解析PHP的session过期设置
下一篇: 循环&运算符