I can't seem to send a request to report server using HttpClient as the result is always 401 (Unauthorized).
The action is
public async Task<FileStreamResult> SSRSTest()
{
//set credentials
using (var handler = new HttpClientHandler {
Credentials = new NetworkCredential("userName", "password"),
UseDefaultCredentials = false
})
using (var httpClient = new HttpClient(handler))
{
//get *.pdf from report server
var response = await httpClient .GetStreamAsync("http://someip/ReportServer/Pages/ReportViewer.aspx?TheRemainingPartOfURL");
var contentDisposition = new ContentDisposition
{
FileName = "SomeReport.pdf",
Inline = false
};
//set content disposition
Response.AppendHeader("Content-Disposition", contentDisposition.ToString());
//return the file
return File(response, "application/pdf");
}
}
Additional:
Pass a Report Parameter Within a URL
Export a Report Using URL Access
Export Formats
Generate Data Feeds from a Report
I've used Fiddler to see what is going on when i login using browser
the Auth tab is
WWW-Authenticate Header is present: Negotiate
WWW-Authenticate Header is present: NTLM
so even though I was told that the authentication is Basic i needed to use the following
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(new Uri("http://youruri"),"NTLM",new NetworkCredential(username, password));
using (var handler = new HttpClientHandler
{
Credentials = credentialCache
})
The rest of the code for HttpClient is the same.
Additional:
Authentication with the Report Server
Selecting a Credential Type
Understanding SQL Server Reporting Services Authentication
Configure Basic Authentication on the Report Server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With