0

this is what i tried:

Future<User> guestLogin(String deviceID) async {
  var body = {
    "deviceid": deviceID,
  };

  var bodyEncoded = json.encode(body);

  Response response = await client.post(
    "$_baseURL/api/user/guest",
    body: bodyEncoded,
    headers: {"Content-Type": "application/json"},
  );
  return User.fromJson(json.decode(response.body));
} 

but when i check it from serverside which coded by golang then i see that the body is empty. when i try it on postman its working well. Where is the problem?

9
  • What's the response status? Commented Aug 1, 2020 at 21:35
  • @ClaudioRedi it's 200 Commented Aug 1, 2020 at 21:35
  • What do you expect as body? Commented Aug 1, 2020 at 21:37
  • a user model. @ClaudioRedi . But flutter send post body as empty Commented Aug 1, 2020 at 21:39
  • Hard to tell from the code you show. Do you own the api to check why the response is empty? Commented Aug 1, 2020 at 21:44

1 Answer 1

1

try jsonEncode(body) instead of json.encode(body)

Sign up to request clarification or add additional context in comments.

1 Comment

jsonEncode(body) and json.encode(body) are exactly the same @Ali Gürelli.... look at the definition api.dart.dev/stable/2.9.0/dart-convert/jsonEncode.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.