1

I am making posts like this:

curl 'http://localhost/api.php' -H 'Content-Type: application/json' --data 'names=[{"name":"name"}]'

Which results in the post data being deleted.

If I remove the content-type header, e.g.

curl 'http://localhost/api.php' --data 'names=[{"name":"name"}]'

The post data is present.

The Nginx congiuraiton consists of this:

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/;

server_name _;

location ~ \.php$
{
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}   

location / {
    try_files $uri $uri/ =404;
    index index.html; 
    autoindex on;
}
}

Does anyone have any insight into why this is?

Kohjah Breese
  • 171
  • 2
  • 13

1 Answers1

3

I doubt this is Nginx's doing. Try

curl -H 'Content-Type: application/json' -d 'names=[{"name":"name"}]' 'http://localhost/api.php'

PHP does receive the json data, but the only way I could retrieve it, was

    $json = file_get_contents('php://input');
    var_dump($json);

which gave

string(23) "names=[{"name":"name"}]"

Even phpinfo() would not show the data, only the headers type and content size.

I had forgotten about GeekForGeeks howto

Gerard H. Pille
  • 2,569
  • 1
  • 13
  • 11
  • Thanks for the suggest. The same error occurs. Do you think it may be PHP? It is nothing to do with any code as I tried printing the POST before any other code. – Kohjah Breese Dec 23 '20 at 08:27
  • I am getting this on both my local (dev) and remote (live) server. The Nginx config for them is not the same. – Kohjah Breese Dec 23 '20 at 09:25
  • Replace api.php by a page containing nothing but a phpinfo();. Then you'll see what PHP receives. Alternatively, let php-fpm listen on a tcp port iso. a socket. Then run tcpdump on that port. If the data isn't there, run tcpdump on port 80. This way you obtain proof of where the data is lost. – Gerard H. Pille Dec 23 '20 at 09:51
  • See my edited answer. – Gerard H. Pille Dec 23 '20 at 10:19