"xxxx",);$data = json_encode($param);list($return_code, $return_content) = http_po" />

百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>网页制作> PHP基于curl模拟post提交json数据示例
分享文章到:

PHP基于curl模拟post提交json数据示例

发布时间:05/20 来源:未知 浏览: 关键词:

本文实例讲述了PHP基于curl模拟post提交json数据。分享给大家供大家参考,详细如下:

这里php模拟post提交json数据操纵的关键是在头部设置Content-Type

"test001",
  "pass"=>"xxxx",
);
$data = json_encode($param);
list($return_code, $return_content) = http_post_data($url, $data);//return_code是http状态码
print_r($return_content);exit;
function http_post_data($url, $data_string) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json; charset=utf-8",
    "Content-Length: " . strlen($data_string))
  );
  ob_start();
  curl_exec($ch);
  $return_content = ob_get_contents();
  ob_end_clean();
  $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  return array($return_code, $return_content);
}

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有159人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板