php - 检测 PHP 中的请求类型(GET、POST、PUT 或 DELETE)

标签 php http request

如何检测 PHP 中使用了哪种请求类型(GET、POST、PUT 或 DELETE)?

最佳答案

通过使用

$_SERVER['REQUEST_METHOD']

示例

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
     // The request is using the POST method
}

更多详情请查看documentation for the $_SERVER variable .

关于php - 检测 PHP 中的请求类型(GET、POST、PUT 或 DELETE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/359047/

相关文章:

reactjs - axios get请求在React中第一次返回undefined

php_network_getaddresses : getaddrinfo failed: Name or service not known what do i do

php - Codeigniter CSRF 保护 VS 选项卡

php - Silverstripe:ConfirmedPasswordField 不保存新密码

php - 使用 Laravel 护照 oauth/token 发送更多数据

php - Golang vs PHP https 调用具有不同的 header 结果

http - 被阻止的滥用用户的正确 HTTP 状态代码是什么?

python - 如何在 BaseHTTPRequestHandler 子类中停止 BaseHTTPServer.serve_forever()?

android - 列出来自 Android 手机的 HTTP 请求

python - 如何在 request.post 方法中使用 json 和 files 参数上传文件