【发布时间】:2009-04-26 21:41:09
【问题描述】:
我正在尝试从 TFS 服务器上的报告服务实例下载一些数据。
鉴于代码应该在未加入域的计算机上运行,我想我会自己设置凭据。不走运,得到了 HTTP 401 Unauthorized 回复。好的,所以我连接了 Fiddler 看看发生了什么。
但那是我接到Heisenberged 的时候——电话现在顺利通过了。因此,身份验证在 Fiddler 连接的情况下通过,但没有它就失败。 Webclient 是坏了还是我在这里遗漏了一些深刻的东西?
private void ThisWorksWhenDomainJoined()
{
WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultNetworkCredentials;
wc.DownloadString("http://teamfoundationserver/reports/........"); //Works
}
private void ThisDoesntWork()
{
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("username", "password", "domain");
wc.DownloadString("http://teamfoundationserver/reports/........"); //blows up wih HTTP 401
}
【问题讨论】:
-
+1 将海森堡不确定原理用作动词,以前从未听说过!
标签: c# webclient system.net