php http method,php – 什么是$_SERVER [‘HTTP_X_HTTP_METHOD’]

标签: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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值