您现在的位置是:网站首页> 编程资料编程资料
PHP基于curl模拟post提交json数据示例_php技巧_
2023-05-25
210人已围观
简介 PHP基于curl模拟post提交json数据示例_php技巧_
本文实例讲述了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); } PS:这里再为大家推荐几款比较实用的json在线工具供大家参考使用:
在线JSON代码检验、检验、美化、格式化工具:
http://tools.jb51.net/code/json
JSON在线格式化工具:
http://tools.jb51.net/code/jsonformat
在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson
json代码在线格式化/美化/压缩/编辑/转换工具:
http://tools.jb51.net/code/jsoncodeformat
C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php curl用法总结》、《PHP网络编程技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》及《PHP中json格式数据操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
相关内容
- PHP获取日期对应星期、一周日期、星期开始与结束日期的方法_php技巧_
- PHP实现将base64编码字符串转换成图片示例_php技巧_
- PHP实现正则匹配所有括号中的内容_php实例_
- PHP实现 APP端微信支付功能_php实例_
- thinkPHP实现基于ajax的评论回复功能_php实例_
- php strftime函数的详细用法_php基础_
- PHP获取本周所有日期或者最近七天所有日期的方法_php实例_
- ThinkPHP5.0 图片上传生成缩略图实例代码说明_php实例_
- thinkPHP框架实现的短信接口验证码功能示例_php实例_
- thinkPHP3.2.2框架行为扩展及demo示例_php实例_
