【转】file_get_contents(php://input)的使用方法
$data = file_get_contents("php://input");
php://input 是个可以访问请求的原始数据的只读流。 POST 请求的情况下,最好使用 php://input 来代替 $HTTP_RAW_POST_DATA,因为它不依赖于特定的 php.ini 指令。 而且,这样的情况下 $HTTP_RAW_POST_DATA 默认没有填充, 比激活 always_populate_raw_post_data 潜在需要更少的内存。 enctype="multipart/form-data" 的时候 php://input 是无效的。
1, php://input 可以读取http entity body中指定长度的值,由Content-Length指定长度,不管是POST方式或者GET方法提交过来的数据。但是,一般GET方法提交数据 时,http request entity body部分都为空。
2,php://input 与$HTTP_RAW_POST_DATA读取的数据是一样的,都只读取Content-Type不为multipart/form-data的数据。
学习笔记
1,Coentent-Type仅在取值为application/x-www-data-urlencoded和multipart/form-data两种情况下,PHP才会将http请求数据包中相应的数据填入全局变量$_POST
2,PHP不能识别的Content-Type类型的时候,会将http请求包中相应的数据填入变量$HTTP_RAW_POST_DATA
3, 只有Coentent-Type为multipart/form-data的时候,PHP不会将http请求数据包中的相应数据填入php://input,否则其它情况都会。填入的长度,由Coentent-Length指定。
4,只有Content-Type为application/x-www-data-urlencoded时,php://input数据才跟$_POST数据相一致。
5,php://input数据总是跟$HTTP_RAW_POST_DATA相同,但是php://input比$HTTP_RAW_POST_DATA更凑效,且不需要特殊设置php.ini
6,PHP会将PATH字段的query_path部分,填入全局变量$_GET。通常情况下,GET方法提交的http请求,body为空。
例子
1.php用file_get_contents("php://input")或者$HTTP_RAW_POST_DATA可以接收xml数据
【转】file_get_contents(php://input)的使用方法相关推荐
- file_get_contents(php://input)的使用方法
$data = file_get_contents("php://input"); php://input 是个可以访问请求的原始数据的只读流. POST 请求的情况下,最 ...
- php input 只接收文件内容,一文搞懂$_POST和file_get_contents(“php://input”)的区别
今天来说一说 $_POST.file_get_contents("php://input")和$GLOBALS['HTTP_RAW_POST_DATA']的区别,这三个方法都是用来 ...
- file_get_contents(php://input)
$data = file_get_contents("php://input"); php://input 是个可以访问请求的原始数据的只读流. POST 请求的情况下,最好使用 ...
- php://input的使用方法
$data = file_get_contents("php://input"); 简述 php://input是个可以访问请求的原始数据的只读流.POST请求的情况下,最好使用p ...
- file_get_contents('php://input') 和POST的区别
之前记得写过这2者的区别,今天看群里有个朋友也提出了怪异的问题,说是"file_get_contents('php://input')获取不到curl post请求的数据的问题"? ...
- fastjson转换包含date类型属性的对象时报错com.alibaba.fastjson.JSONException: For input string 解决方法
fastjson转换包含date类型属性的对象时报错com.alibaba.fastjson.JSONException: For input string 解决方法 pojo里面的date属性上要加 ...
- ios手机端 表单input调用focus方法时,光标不显示,但软键盘会弹出来,可以修改内容,需要修改内容后光标才显示
功能: ios表单验证时,比如 输身份证号,失焦后验证身份证,如果不合法,就让光标跳到对应的输入框,我是不合法就调用focus方法,完了会跳过去,但是ios有个bug,它确实会定位到对应的输入框,而且 ...
- 小程序-获取input值的方法
微信小程序-获取input值的方法 1. bindinput wxml <input name="text_name" type='text' bindinput='getV ...
- file_get_contents设置响应时间timeout的方法
curl有curlopt_connecttimeout可设,fsockopen有$timeout可设,而file_get_contents和fopen在打开url时,都不可设置响应时间timeout. ...
最新文章
- winpython是个坑_Win10 Python MySQLdb安装爬的坑
- [reference]-ARM core timeline
- 2021-10-09 求二叉树的高度(递归和迭代版本)
- 在Linux下如何安装QQ?
- Linux下网络流量实时监控工具大全
- javascript知识点总结----Function定义
- html二维坐标系转换,旋转坐标系 转换工具
- Node.js和io.js将合并到Node基金会下
- Android APK系列5-------修改APK中的内容
- 小美赛之matlab笔记
- web制作、开发人员需知的Web缓存知识
- OpenHarmony命令行工具hdc_std使用总结
- practice之Python爬取今日头条图片(正则表达式)
- 记录:ERROR YarnScheduler: Lost executor 2 on XXX: Container killed by YARN for exceeding memory limits
- weblogic子服务器显示状态RESUMING,长期等待状态
- A Game of Thrones(101)
- 常用计算机高级语言及其特点,计算机高级语言特点是什么?常见的语种有哪些?...
- 《Optimizing Java》读书笔记中
- Unresolved reference: synthetic 【Android】【Android Studio】【kotlin-android-extensions】
- 我的世界服务器给个人修改前缀,我的世界怎么给名字添加前后缀_给玩家添加名字前后缀方法介绍_3DM网游...