I am trying this code to get a SSRS report from the SSRS server:
var uri = new Uri("https://localhost/Reports/report/Fault%20Diagnostics%20Coverage%20Summary");
var credentialsCache = new CredentialCache();
credentialsCache.Add(uri, "Negotiate", new NetworkCredential("domain\\username", "password"));
var handler = new HttpClientHandler() { Credentials = credentialsCache, PreAuthenticate = true };
using (var client = new HttpClient(handler))
{
var response = client.GetAsync("https://localhost/Reports/report/reportname").Result;
if (response.IsSuccessStatusCode)
{
var responseContent = response.Content;
// by calling .Result you are synchronously reading the result
string responseString = responseContent.ReadAsStringAsync().Result;
Response.Write(responseString);
}
}
I was able to get this code working but lost that code. Now all I get is this:
System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure
Please help.
Thanks
Update: After adding this code:
handler.ServerCertificateCustomValidationCallback =
(httpRequestMessage, cert, cetChain, policyErrors) =>
{
return true;
};
I am getting 401.