Home > Blockchain >  Flutter POST request body returns empty
Flutter POST request body returns empty

Time:09-06

  String url = 'http://localhost:49430/#/';
  Future save() async {
    var b = json.encode({'email':user.email, 'password':user.password});
    var res = await http.post(Uri.parse(url),
        headers: {'Content-Type' : 'application/json'},
        body : b,);
    print(b);
    print(res.body);
  }

I am attempting to post the username and password, although when I try to print the json body, it returns as empty. There is a server response of 404, which I believe points to the URL being wrong, although it is not. When I print string b, it prints correctly, so it is clearly something to do with the server.

When I print(Uri.base), it returns with the same URL.

CodePudding user response:

it is local server you need to sure it is already running

CodePudding user response:

Instead of sending body as string try send it as map, like this:

 var b = {'email':user.email, 'password':user.password};

and also your url only contains base url, and doesn't have any end point to refer to specific api.

  • Related