file_get_contents("php://input") 或 $HTTP_RAW_POST_DATA,哪个更适合获取 JSON 请求的正文? [英] file_get_contents("php://input") or $HTTP_RAW_POST_DATA, which one is better to get the body of JSON request?

查看:35
本文介绍了file_get_contents("php://input") 或 $HTTP_RAW_POST_DATA,哪个更适合获取 JSON 请求的正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

file_get_contents("php://input")$HTTP_RAW_POST_DATA - 哪个更好地获取 JSON 请求的正文?

file_get_contents("php://input") or $HTTP_RAW_POST_DATA - which one is better to get the body of JSON request?

当使用客户端 XmlHTTPRequest 时,我应该使用哪种请求类型(GETPOST)来发送 JSON 数据?

And which request type (GET or POST) should I use to send JSON data when using client side XmlHTTPRequest?

我的问题灵感来自这个答案:如何使用 curl 将 JSON 发布到 PHP

My question was inspired from this answer: How to post JSON to PHP with curl

引用那个答案:

从协议的角度来看,file_get_contents("php://input") 实际上更正确,因为您实际上并没有真正处理 http 多部分表单数据.

From a protocol perspective file_get_contents("php://input") is actually more correct, since you're not really processing http multipart form data anyway.

推荐答案

实际上 php://input 允许你读取原始 POST 数据.

Actually php://input allows you to read raw POST data.

它是 $HTTP_RAW_POST_DATA 的内存密集型替代方案,不需要任何特殊的 php.ini 指令.

php://input 不适用于 enctype="multipart/form-data".

参考: http://php.net/manual/en/wrappers.php.php

这篇关于file_get_contents("php://input") 或 $HTTP_RAW_POST_DATA,哪个更适合获取 JSON 请求的正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆