最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
平安快乐赛车开奖结果
时间:2018-06-25 13:56:39 编辑:猪哥 来源:转载
本文实例讲述了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); }
相关文章
- PHP远程连接oracle数据库操作实现方法图文详解04-11
- 在CentOS上安装搭建PHP+Apache+Mysql的服务器环境方法03-21
- PHP使用SOAP调用API操作示例12-25
- 详解PHP实现支付宝小程序用户授权的工具类12-25
- PHP后期静态绑定实例浅析12-23
- php json转换相关知识(小结)12-23
文章评论