Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Response body is empty in http call

I am calling a remote PHP file to get some data into my Flutter app.

This is the Flutter function:

 Future<void> registrarUsuario() async {


    var url = Constantes.adminUsuariosUrl + 'nuevo_usuario.php';
    final response = await http.post(Uri.parse(url), body: {
      "email": controllerEmail.text,
      "password": controllerPass.text
    });

    print("response ${response.body}");

  }

Calling the function the print output is empty.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

flutter: response

But calling the PHP file using Postman gives me the following output:

[{"id":"57","correo":"modestovasco@gmail.com"}]

I would like to update the funtion registrarUsuario to get the json objects from the response.body

>Solution :

Encode the body content in request


 Future<void> registrarUsuario() async {


    var url = Constantes.adminUsuariosUrl + 'nuevo_usuario.php';
    final response = await http.post(Uri.parse(url), body:json.encode({
      "email": controllerEmail.text,
      "password": controllerPass.text
    }));

    print("response ${response.body}");

  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading