mvasco
mvasco

Reputation: 5107

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.

flutter: response

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

[{"id":"57","correo":"[email protected]"}]

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

Upvotes: 1

Views: 745

Answers (1)

Sugan Pandurengan
Sugan Pandurengan

Reputation: 723

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}");

  }

Upvotes: 1

Related Questions