php - 无法使用 file_get_contents ('php://input' 检索原始发布数据)

标签 php post file-get-contents postman

这是我的代码。我正在使用 post 方法发布我的数据。

$post_body = file_get_contents('php://input');
if(getenv('REQUEST_METHOD') == 'POST'){
    print_r( array( "3","3d"));
}
print_r($post_body);

我正在使用 chrome 的 postman 来测试此代码,但它不打印发布数据,请参阅输出图像。

output image

我做错了什么???

编辑

为了展示我是如何解决我的问题的,我添加了这张图片。

To show

最佳答案

根据 PHP documentation

php://input is not available with enctype="multipart/form-data".

Postman 支持不同类型的 Content-Type 包括 multipart/form-data 这似乎是默认的。

因此请确保您不使用multipart/form-data(在Body 选项卡中)。

关于php - 无法使用 file_get_contents ('php://input' 检索原始发布数据),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37019791/

相关文章:

php - 如何在不添加任何索引的情况下插入更新重复项

javascript - fancybox ajax 发布到 iframe

php - Javascript:postAjax 不发布任何内容

php - 将文本/javascript 加载到 PHP 页面中

php - 错误 file_get_contents() : read of 8192 bytes failed with errno=21

PHP读取带有日语单词的url内容

PHP imagecreatefromjpeg 有效,那么为什么 png/bmp/gif 无效?

php - 如何根据父下拉列表选择动态选择子下拉列表

php - 检查数据库中是否存在记录

java - 将时间戳添加到 HashMap 帖子。如何?