1

我想从网站下载某个文件。为此,我尝试使用这个

WebProxy p = new WebProxy("192.168.10.254:8080", true);
p.Credentials = new NetworkCredential("username", "pwd");
WebRequest.DefaultWebProxy = p;
WebClient client = new WebClient();
string downloadString = client.DownloadString("myDowloadUrl");

每次,我都会收到此网络异常

远程服务器返回错误:(401) Unauthorized。

有什么线索吗?

4

1 回答 1

2

我建议始终保持简单。尝试这个

       using (var Client = new WebClient())
        {
            Client.Credentials = new System.Net.NetworkCredential("username", "pwd");
            Client.DownloadFile("myDowloadUrl", @"downloadFilelocalpath");
        }
于 2014-01-01T06:23:01.593 回答