doujia4759 2014-07-20 21:20
浏览 24

如何捕获发布到PHP脚本的任何内容,即使它格式不正确?

For example, properly formatted would look something like this (I just did a var_dump on incoming POST request):

array(1) { ["fred"]=> string(6) "barney" }

But what if I sent badly formatted/mangled data, like the naked string "test"?

This is what I'm trying to capture. I'm sending it with the postman chrome extension. My script dumps all of POST into a log file, but since it's just the word "test", it doesn't show up. How would I capture this and all other cases of data sent to my script?

  • 写回答

1条回答 默认 最新

  • dsgs8208 2014-07-20 21:29
    关注

    You can use the php://input stream to get the data you want.

    http://us.php.net/manual/en/wrappers.php.php

    This is the prefered method instead of using $HTTP_RAW_POST_DATA, because:

    it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".

    Example: var_dump(file_get_contents('php://input'));

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算