首页 > Web开发 > 详细

使用 PHP cURL 提交 JSON 数据

时间:2016-05-09 15:50:40      阅读:206      评论:0      收藏:0      [点我收藏+]
$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 cURL 提交 JSON 数据

原文:http://www.cnblogs.com/shanyansheng/p/5474110.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!