Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.

Test Rail Api response contains invalid character


Hi all,
we are hosting TestRail within our company and are running at Windos/Microsoft Information Server…

After calling the TestRail Api we receive the following Exception during parsing the answer:
Parse Exception,
Unexpected character () at position 0.

Indeed the first byte seems to be a questionmark.

The byte stream is encoded as UTF-8
BufferedReader reader = new BufferedReader(new InputStreamReader(istream, “UTF-8”));

and the HTTP request header looks like:
{GET /index.php?/api/v2/get_projects HTTP/1.1: null}{Content-Type: application/json}{Authorization: Basic cnQ2NTpOaWtGbG9yaTA4JA==}{User-Agent: Java/1.6.0_45}{Host: XXXXXXXXXX}{Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2}{Connection: keep-alive}

and the Http response header:
{null: HTTP/1.1 200 OK}{Content-Type: application/json; charset=utf-8}{Server: Microsoft-IIS/7.5}{X-Powered-By: PHP/5.5.25}{X-Powered-By: ASP.NET}{Date: Wed, 10 Jun 2015 07:28:53 GMT}{Content-Length: 767}

Any ideas?


Solution found,
the server is sending a BOM and this can be removed via the Java class BOMInputStream



Just to clarify this: the API does not actually return a BOM but this is likely caused by something else (such as a BOM at the beginning of the config.php outside of TestRail’s control which was added by a text editor for example).