C# 使用c从代理服务器下载文件#

C# 使用c从代理服务器下载文件#,c#,.net,C#,.net,我想使用代理连接下载文件。我的示例代码是: WebClient client = new WebClient(); WebProxy wp = new WebProxy("url_proxy_server"); //wp.Credentials = new NetworkCredential("id", "pass", "domain"); client.Proxy = wp; client.DownloadFile

我想使用代理连接下载文件。我的示例代码是:

        WebClient client = new WebClient();
        WebProxy wp = new WebProxy("url_proxy_server");
        //wp.Credentials = new NetworkCredential("id", "pass", "domain");
        client.Proxy = wp;
        client.DownloadFile("http:mylink", "Save Path");

这是正确的下载模式吗?如何设置端口号?

使用其他构造函数(字符串,Int32)

WebProxy wp=新的WebProxy(“http://contoso", 80);


您还可以在代理url中指定端口

WebProxy wp = new WebProxy("url_proxy_server:proxyPort");