In PHP Linux Azure Web App, $_SERVER['REQUEST_METHOD'] is always set to GET, even when POST, PATCH, DELETE etc requests are made through Postman
Get the solution ↓↓↓I have a PHP app hosted on a Linux Azure App Service, which has a RESTful API component.
Inside the code for the endpoints, I have the following code for determining what type of request was made:
if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) { ...
}
else if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) { ...
}
else if ( $_SERVER['REQUEST_METHOD'] == 'PATCH' ) { ...
}
else if ( $_SERVER['REQUEST_METHOD'] == 'DELETE' ) { ...
else { ...
}
When the PHP app is hosted locally and the API is tested with Postman, this works fine. However, when the app is hosted on Azure, the$_SERVER['REQUEST_METHOD']
variable always returns'GET'
, no matter what the actual request method is set to in Postman.
I have done some looking into it, and found a Stack Overflow answer that said that the$_SERVER['REQUEST_METHOD']
variable is always set to'GET'
by default: https://stackoverflow.com/a/34984252/14461562.
However I have been unable to find any more information on how to get the$_SERVER['REQUEST_METHOD']
variable to work properly.
Does anyone have experience with this issue or know how to go about solving it?
Answer
Solution:
Maybe you don't have redirect rules or use wrong rules.
Add.htaccess
file with below code, maybe useful to you.
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: trying to access array offset on value of type bool
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.