Using HttpClient inside an ASP.NET MVC Action to Call SSRS

I cannot send a request to the report server using HttpClient , since the result is always 401 (unauthorized) .

Act

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");
                }
            }

Additionally:

Passing a report parameter inside a URL

Export report using URL access

Export Formats

Creating data feeds from a report

+4
source share
1 answer

I used Fiddler to find out what happens when I log in using a browser

enter image description here

Auth tab -

WWW-Authenticate Header is present: Negotiate    
WWW-Authenticate Header is present: NTLM

therefore, although I was told that authentication is Basic, I need 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
            })

HttpClient - .

:

SQL Server

+1

All Articles