Spark Core Http Client Library

Thanks @Dave!

While adding support for custom HTTP headers today, I noticed that there is an extra character being sent along with the intended string when using the TCP Client. Either the TCP Client is adding an extra character to the beginning of strings being sent or (quite possibly) the reason for that character has something to do with C++ strings and might not have anything to do with the Spark firmware. I thought I’d share it here just in case, maybe the explanation is easy.

I send the HTTP request body like this:

Application.cpp:

  request.body = "{\"key\":\"value\"}";

HttpClient.cpp

  // Empty line to finish HTTP Headers
  client.println();
  client.flush();

  // Send HTTP Request body.
  client.println(aRequest->body);

And for some reason jsontest.com responds with an error, saying there is a character before the first curly brace in the string:
“error”: “A JSONObject text must begin with ‘{’ at 1 [character 2 line 1]”

I haven’t looked too deeply in the TCP Library, but since that is used for many things I’d assume it rather bug-free.

It’s not a big deal, any JSON parser will probably strip leading and trailing whitespace anyway, but I’m guessing it shouldn’t be there.