PUT API 尸体在邮差/失眠中失踪
PUT API body missing in Postman / Insomnia
我正在向 Postman 和 Insomnia 等应用程序发送 API 请求。
我可以发送一个 POST 带有表单数据主体的请求,这样它看起来像
parameters:[{"fullname" : "John Smith", "username" : "jsmith", "email" : "jsmith@example.com", "password" : "s348nfdf"},{"fullname" : "Janine Smith", "username" : "jsmith1", "email" : "jsmith1@example.com", "password" : "ddfgret567"}]↵
一切正常,我可以从后端的请求中获取参数。
但是,如果我将请求更改为 PUT,主体(上面的参数)不在请求中($_REQUEST)。请求本身是成功的,没有错误代码。
我也试过 x-www-form-urlencoded 和 raw JSON。
为什么body(参数)不见了?
$_REQUEST[]
中没有尸体。使用:
$body = file_get_contents('php://input');
来自 PHP manual entry on I/O 流文档:
php://input is a read-only stream that allows you to read raw data
from the request body. In the case of POST requests, it is preferable
to use php://input instead of $HTTP_RAW_POST_DATA as 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".
我正在向 Postman 和 Insomnia 等应用程序发送 API 请求。
我可以发送一个 POST 带有表单数据主体的请求,这样它看起来像
parameters:[{"fullname" : "John Smith", "username" : "jsmith", "email" : "jsmith@example.com", "password" : "s348nfdf"},{"fullname" : "Janine Smith", "username" : "jsmith1", "email" : "jsmith1@example.com", "password" : "ddfgret567"}]↵
一切正常,我可以从后端的请求中获取参数。
但是,如果我将请求更改为 PUT,主体(上面的参数)不在请求中($_REQUEST)。请求本身是成功的,没有错误代码。
我也试过 x-www-form-urlencoded 和 raw JSON。
为什么body(参数)不见了?
$_REQUEST[]
中没有尸体。使用:
$body = file_get_contents('php://input');
来自 PHP manual entry on I/O 流文档:
php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as 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".