[英]How to get PUT content from HTTP request in PHP
I am trying to declare HTTP PUT
variable in php. 我正在尝试在php中声明HTTP
PUT
变量。 This is my code: 这是我的代码:
<?php
${"_" . $_SERVER['REQUEST_METHOD']} = /* What should be here? */;
?>
I tried var_dump($_SERVER)
but it does not contain the data sent using ajax request. 我尝试了
var_dump($_SERVER)
但是它不包含使用ajax请求发送的数据。 I am sure there is no problem with $.ajax()
. 我确定
$.ajax()
没有问题。
While there is no official $_PUT
variable in PHP, you can create one yourself like this: 虽然PHP中没有官方的
$_PUT
变量,但是您可以这样创建自己:
$method = $_SERVER['REQUEST_METHOD'];
if ('PUT' === $method) {
parse_str(file_get_contents('php://input'), $_PUT);
var_dump($_PUT); //$_PUT contains put fields
}
Source: https://stackoverflow.com/a/41959141/4379151 资料来源: https : //stackoverflow.com/a/41959141/4379151
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.