2

Does anyone know why I keep getting Error 400 Parse Error when POST to App Engine? My JSON is fine. I have JSON.encoded it. Anyone run into these issues before???

This is my HTTPRequest code.

sendData = JSON.encode(data);

_httpRequest = new HttpRequest()
        ..open(method, url)
        ..setRequestHeader("Authorization", "Bearer " + tokenKey)
        ..onLoadEnd.listen((e) => _loadEnd(_httpRequest))
        ..send(sendData);
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
robbie
  • 269
  • 1
  • 9

1 Answers1

2

Don't forget to specify the headers as Content-type: application/json as without it the data is text/html. Silly mistake.

Updated POST here:

sendData = JSON.encode(data);

_httpRequest = new HttpRequest() ..open(method, url) ..setRequestHeader("Authorization", "Bearer " + tokenKey) ..setRequestHeader("Content-type", "application/json") ..onLoadEnd.listen((e) => _loadEnd(_httpRequest)) ..overrideMimeType("application/json") ..send(sendData);

robbie
  • 269
  • 1
  • 9