我正在尝试获取某个网页的 html 代码, 我有一个正确的用户名和密码,但我仍然无法使用它, 这是我的代码:
private void buttondownloadfile_Click(object sender, EventArgs e)
{
NetworkCredentials nc = new NetworkCredentials("?", "?", "http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");
WebClient client = new WebClient();
client.Credentials = nc;
String htmlCode = client.DownloadString("http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");
MessageBox.Show(htmlCode);
}
MessageBox只是为了测试它, 问题是每次我到达这一行时:
String htmlCode = client.DownloadString("http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");
我得到一个异常(exception):
The remote server returned an error: (401) Unauthorized.
我该如何解决这个问题?
最佳答案
在我的例子中,client.UseDefaultCredentials = true;
成功了。
关于c# - 远程服务器返回错误 : (401) Unauthorized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2038808/