file_get_contents(quot;php://inputquot;) or $HTTP_RAW_POST_DATA, which one is better to get the body of JSON request?(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
时,我应该使用哪种请求类型(GET
或 POST
)来发送 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
可以让你读取原始请求体.
Actually php://input
allows you to read raw request body.
它是 $HTTP_RAW_POST_DATA 的内存密集型替代方案,不需要任何特殊的 php.ini 指令.来自 参考
php://input
不适用于 enctype=multipart/form-data"
.
这篇关于file_get_contents("php://input") 或 $HTTP_RAW_POST_DATA,哪一个更适合获取 JSON 请求的正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:file_get_contents("php://input") 或 $HTTP_RAW_POST_DATA,哪一个更适合获取 JSON 请求的正文?


基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01