标签:php
我正在阅读REST api here的解释,那里有以下代码块:
$this->method = $_SERVER['REQUEST_METHOD'];
if ($this->method == 'POST' && array_key_exists('HTTP_X_HTTP_METHOD', $_SERVER)) {
if ($_SERVER['HTTP_X_HTTP_METHOD'] == 'DELETE') {
$this->method = 'DELETE';
} else if ($_SERVER['HTTP_X_HTTP_METHOD'] == 'PUT') {
$this->method = 'PUT';
} else {
throw new Exception("Unexpected Header");
}
}
我的问题是什么是$_SERVER [‘HTTP_X_HTTP_METHOD’]?我已经google了,我发现的唯一的事情是使用X-HTTP-Method-Override标头通过POST方法传输所需的执行方法.实际上上面的代码似乎正在做它.它也是吗?
解决方法:
the X-HTTP-Method header can be added to a POST request that signals that the server MUST process the request not as a POST, but as if the HTTP verb specified as the value of the header was used as the method on the HTTP request’s request line, as specified in [RFC2616] section 5.1. This technique is often referred to as “verb tunneling”.
简而言之,标题中的真实HTTP谓词将是POST,但应用程序将查找此特殊标头,以确定模拟HTTP谓词实际意味着什么类型的请求.
然后,它在$_SERVER []下,因为它是作为HTTP标头发送的.大多数HTTP标头都可以在$_SERVER数组下访问,并以HTTP_为前缀.
标签:php
来源: https://codeday.me/bug/20190528/1173356.html