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?
问题描述
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
允许您读取原始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屋!