Jasper server rest service returns unauthorized

982 Views Asked by At

Using .NET Http client i login to jasper server.

 HttpResponseMessage loginResponse = loginClient.PostAsync("http://localhost:8080/jasperserver/rest/login", formContent).Result;
IEnumerable<string> jaspsessid = loginResponse.Headers.GetValues("Set-Cookie");

Using above session id i pass to next request.

HttpClient httpClient = new HttpClient();
        httpClient.DefaultRequestHeaders.Add("Cookie", jaspsessid);
            httpClient.DefaultRequestHeaders.Accept.Add(new 

System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
StringContent requestContent = constructJasperRequestJson(reportParameters);
HttpResponseMessage generateReportRequestResponse = new HttpResponseMessage();
generateReportRequestResponse = httpClient.PostAsync(AppConstant.JASPER_SERVER_BASE_URI + AppConstant.JASPER_SERVER_REPORT_EXECUTION_URI, requestContent).Result;

In second request i am getting 401.Unauthorized.

If anyone knows the issue,help me.

1

There are 1 best solutions below

0
On BEST ANSWER

You could use a CookieContainer to hold the session cookie, rather than setting a header.

See How do I set a cookie on HttpClient's HttpRequestMessage for an example.