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

Java REST Call Help Needed


I’m trying to get the RESTful service working from Java. So far I’ve gotten pretty far in that I can use curl to verify the REST call works (get_projects) and I can connect to the RESTful service with the Java client. However, for the life of me I can’t seem to get the java app to send the “Content-Type: application/json” header. I’m using Spring’s RestTemplate which has worked great for other projects. Anyone out there have a working example I can take a look at, even if it’s not using RestTemplate?


I hope i understood you correct.
for many requests in Testrail i think you need three tings:

  1. tr_session (Header/Cookie)
  2. tr_rememberme (Header/Cookie)
  3. _token
    If Point 2 is needed i do not know.

to get them you need to perform a login-request:
Content-Type = “application/x-www-form-urlencoded”
url encoded:

In the response you get the overview page. also the Token is given. To extract it filter by regex:
name="_token" value="(.*?)"

example c# code:
HttpClient client = new HttpClient();

// Form Data
var dict = new Dictionary<string, string>
{ “name”, "" },
{ “password”, “xxxx” },
{ “rememberme”, “1” }
FormUrlEncodedContent content = new FormUrlEncodedContent(dict);
string url = “xxx/index.php?/auth/login/=”
//perform Request
HttpResponseMessage response = await client.PostAsync(url, content);

            //get response body
            string responseBody = await response.Content.ReadAsStringAsync();

            //Filter token
            Match match = Regex.Match(responseBody, "name=\"_token\" value=\"(.*?)\"");
            if (match.Success) token = match.Groups[1].Value;
        catch (HttpRequestException e)
            Console.WriteLine("\nException Caught!");