![](/img/trans.png)
[英]redirection to an action with asp.net mvc application using javascript call
[英]Using HttpClient inside ASP.NET MVC Action to call SSRS
我似乎无法使用HttpClient发送报告服务器的请求,因为结果总是401(未经授权) 。
行动是
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");
}
}
额外:
我使用Fiddler来查看使用浏览器登录时发生了什么
Auth选项卡是
WWW-Authenticate Header is present: Negotiate
WWW-Authenticate Header is present: NTLM
所以,即使我被告知身份验证是基本的,我需要使用以下内容
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(new Uri("http://youruri"),"NTLM",new NetworkCredential(username, password));
using (var handler = new HttpClientHandler
{
Credentials = credentialCache
})
HttpClient的其余代码是相同的。
额外:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.