Skip to content
Advertisement

How to send POST request from Flutter app to PHP server

I’ve tried to send a POST request from my Dart application to a PHP file on my server that only checks if $_POST[‘username’] is set, what happens is that the request seems to reach the server but the server refuses to “read it”:

This is what the server sees when a request is received (seen by using: file_get_contents(‘php://input’))

JavaScript

but if I try to do something like:

JavaScript

this always returns false.

Here is the method I use to send the POST request:

JavaScript

why does isset($_POST[‘username’]) not see my POST sent value?

Advertisement

Answer

Your post request from flutter side is correct

JavaScript

will return null as username is part of the json object, It would have worked if :

JavaScript

your request satisfied the above format.

To check for data you can do is :

JavaScript

You can also check for valid json using other methods.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement