设为首页收藏本站

就爱编程论坛

 找回密码
 注册

人人连接登陆

无需注册,直接登录

用新浪微博连接

一步搞定

QQ登录

只需一步,快速开始

查看: 523|回复: 0
打印 上一主题 下一主题

php 中的 $HTTP_RAW_POST_DATA [复制链接]

Rank: 9Rank: 9Rank: 9

  • TA的每日心情
    无聊
    2025-5-27 03:37:20
  • 签到天数: 366 天

    [LV.9]以坛为家II

    论坛先锋 学习至圣 荣誉成员 论坛元老 活跃之星 终极领袖

    我玩的应用:

    跳转到指定楼层
    楼主
    发表于 2012-8-13 00:26:22 |只看该作者 |倒序浏览
    这是手册里写的

    总是产生变量包含有原始的 POST 数据。否则,此变量仅在碰到未识别 MIME 类型的数据时产生。不过,访问原始 POST 数据的更好方法是 php://input。$HTTP_RAW_POST_DATA 对于 enctype="multipart/form-data" 表单数据不可用。

    问题:    $HTTP_RAW_POST_DATA  == $_POST  吗?

    照手册所写 ,答案应该就为否。
    假如不一样的话,他们的区别是什么呢?


    我知道答案了,如下:

    The RAW / uninterpreted HTTP POst information can be accessed with:
       $GLOBALS['HTTP_RAW_POST_DATA']
    This is useful in cases where the post Content-Type is not something PHP understands (such as text/xml).

    也就是说,基本上$GLOBALS['HTTP_RAW_POST_DATA'] 和 $_POST是一样的。但是如果post过来的数据不是PHP能够识别的,你可以用 $GLOBALS['HTTP_RAW_POST_DATA']来接收,比如 text/xml 或者 soap 等等。

    PHP默认识别的数据类型是application/x-www.form-urlencoded标准的数据类型

    用Content-Type=text/xml 类型,提交一个xml文档内容给了php server,要怎么获得这个POST数据。

    The RAW / uninterpreted HTTP POST information can be accessed with:   $GLOBALS['HTTP_RAW_POST_DATA'] This is useful in cases where the post Content-Type is not something PHP understands (such as text/xml).

    由于PHP默认只识别application/x-www.form-urlencoded标准的数据类型,因此,对型如text/xml的内容无法解析为$_POST数组,故保留原型,交给$GLOBALS['HTTP_RAW_POST_DATA'] 来接收。

    另外还有一项 php://input 也可以实现此这个功能

    php://input 允许读取 POST 的原始数据。和 $HTTP_RAW_POST_DATA 比起来,它给内存带来的压力较小,并且不需要任何特殊的 php.ini 设置。php://input 不能用于 enctype="multipart/form-data"。


    应用



    a.htm   
      ------------------   
      <form   action="post.php"   method="post">   
          <input   type="text"   name="user">   
          <input   type="password"   name="password">   
          <input   type="submit">   
      </form>      
       
      post.php   
      ----------------------------   
      <?   echo   file_get_contents("php://input");   ?>   
    分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    分享分享0 收藏收藏0 支持支持0 反对反对0 分享到人人 转发到微博
    [img=http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=fRUcHhYWGAQ9GxIFEBwUEVMeEhA]http://rescdn.qqmail.com/zh_CN/htmledition/images/function/qm_open/ico_mailme_02.png[/img]

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册 人人连接登陆

    晴云孤魂's Blog|就爱编程搜帖|手机版|Archiver|就爱编程论坛     

    GMT+8, 2025-7-1 19:48 , Processed in 0.386729 second(s), 26 queries .

    Powered by Discuz! X2

    © 2001-2011 Comsenz Inc.

    回顶部