当前位置: 移动技术网 > IT编程>开发语言>PHP > 解析PHP 使用curl提交json格式数据

解析PHP 使用curl提交json格式数据

2019年04月07日  | 移动技术网IT编程  | 我要评论

复制代码 代码如下:

$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);

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网