Simple POST results in empty $_POST


#1

I have an Android app making a post to and API but the $_POST array is empty every time. This was working until some point within the last month. No code on the app or the api has been changed recently.

After sometime trying to figure it out, I set up a simple POST in Postman to a PHP script that prints the $_POST and $_REQUEST arrays. Both are always empty. Doing the same thing on another host provides the anticipated results so I’ve concluded something must have changed on the Dreamhost account. Problem is, I have no idea of what would have changed.

Any suggestions as to what I should be checking?


#2

You might see useful PHP error messages in the Apache error logs (e.g. ~/logs/example.com/https/error.log).


#3

Compared the error log before and after a test POST. No change.


#4

I’ve apparently found the cause.

Despite there being no .htaccess file, the www version of the url is redirecting to the non-www version and in doing so, dropping the post data.

The app was posting to the www version. Once that was changed, the problem resolved.

Guess the next question is where/why the redirect is happening and why it is dropping the post data.


#5

Typically, the www vs no-www setup is done in the Panel’s hosting configuration. The odd thing is that you should have seen the redirect page when you made the post request, not an empty result. For example:

$ curl -X POST https://www.example.com
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://example.com/">here</a>.</p>
</body></html>