1

I'm working on a game using the LibGDX library. One part of the game involves collecting game data and sending it to a server as a JSON array to be recorded in a database. I'm using Node as my server but I'm running into an issue every time the game sends a POST request to the server. I'm using LibGDX's Http.Net library to send the request.

I keep getting a HTTP 400 error message and data isn't being recorded. Attached are screenshots of the relevant code and messages. Thank you!

Images: https://i.stack.imgur.com/Xt0UU.jpg

I don't have enough reputation to insert images, sorry.

Peter Xu
  • 51
  • 6
  • possible duplicate of [400 BAD request HTTP error code meaning?](http://stackoverflow.com/questions/19671317/400-bad-request-http-error-code-meaning) – Dalija Prasnikar Jul 29 '15 at 20:40
  • For the future, please don't post your code as images on another website. Instead, just put it directly into your question (as text). Since you've found the solution yourself, you should post it as an answer. Don't edit it into your question. – noone Jul 30 '15 at 05:02
  • Okay, thanks for the tips! Sorry, this was my first post and I don't really know what I'm doing. – Peter Xu Jul 31 '15 at 05:06

1 Answers1

4

I figured out the problem. I was using LibGDX's included JSON library to construct my JSON String. However, when I created Json json = new Json();, it defaults to writing minimal (I think). Names are not surrounded by double quotes in this format. See: https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/JsonWriter.OutputType.html

The solution is to set it to Json json = new Json(JsonWriter.OutputType.json);. This will format it as JSON which Express will recognize.

Peter Xu
  • 51
  • 6