zoukankan      html  css  js  c++  java
  • php服务端接收post的json数据

    最近用到ext与PHP交互,ext把json数据post给PHP,但在PHP里面$_post获取不到,$_REQUEST也获取不到,但是通过firedebug看到的请求信息确实是把JSON数据post给了PHP,这什么情况?
    突然想到了以前接触过flash将图片二进制流传给php,灵机一动用$GLOBALS['HTTP_RAW_POST_DATA']获取到了。于是就深入的查了一下,原来PHP默认只识别application/x-www.form-urlencoded标准的数据类型,因此,对型如text/xml或者 soap 或者 application/octet-stream之类的内容无法解析,如果用$_POST数组来接收就会失败!故保留原型,交给$GLOBALS['HTTP_RAW_POST_DATA']来接收。

    php的HTTP_RAW_POST_DATA
    用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 thepost Content-Type is not something PHP understands (such astext/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");?>
  • 相关阅读:
    Spring 框架学些(二)Spring AOP
    Spring框架学习(一)
    java spring框架的HelloWord
    Windows下查看进程执行参数
    js的code标签显示插件
    初接触hbase数据库
    gpg加密使用
    .net core全球化配置、使用
    CSS添加本地字体
    2011年NOIP普及组复赛题解
  • 原文地址:https://www.cnblogs.com/moqiang02/p/4061380.html
Copyright © 2011-2022 走看看