C# 无法解析代理名称:';http';

C# 无法解析代理名称:';http';,c#,C#,我使用以下脚本下载文件 System.Net.WebClient wc = new System.Net.WebClient(); WebProxy wp = new WebProxy("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357", 80); System.Net.WebClient client = new System.Net.WebClient(); client.Proxy = wp; clien

我使用以下脚本下载文件

System.Net.WebClient wc = new System.Net.WebClient();

WebProxy wp = new WebProxy("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357", 80);
System.Net.WebClient client = new System.Net.WebClient();

client.Proxy = wp;
client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357:80", @"C:\Users\[redacted]\Downloads\DataDetail.csv");
我犯了一个错误

[ERROR] Error: The proxy name could not be resolved: 'http'

如何解决它?

不确定为什么要连接代理(如果需要代理,代理的URL肯定不正确)

我想你可能根本不需要代理:

System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357", @"C:\Users\[YOUR USER NAME]\Downloads\DataDetail.csv");
注:

  • 我从URL末尾删除了不必要的
    :80
  • 给出的响应是JSON,您的代码将其作为CSV下载
  • 您实例化了一个未使用的
    WebClient
    ,我已将其删除

希望这能让您走上正轨。

不确定为什么要连接代理(如果您需要代理,代理的URL肯定不正确)

我想你可能根本不需要代理:

System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357", @"C:\Users\[YOUR USER NAME]\Downloads\DataDetail.csv");
注:

  • 我从URL末尾删除了不必要的
    :80
  • 给出的响应是JSON,您的代码将其作为CSV下载
  • 您实例化了一个未使用的
    WebClient
    ,我已将其删除

希望这能让您走上正轨。

代理服务器的名称必须是“主机名”或IP地址

有效代理服务器名称的示例:

my proxy.example.com(主机名指定为代理服务器)

192.168.10.9(指定为代理服务器的IP地址)

报告的错误显示为
http://api...
不是WebProxy功能的有效输入

如何解决这个问题?

可以通过删除代理服务器或将代理服务器指定为主机名或IP地址来解决此问题

不使用代理服务器的工作代码:

System.Net.WebClient wc = new System.Net.WebClient();

System.Net.WebClient client = new System.Net.WebClient();

client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357:80", @"DataDetail.csv");
System.Net.WebClient wc = new System.Net.WebClient();

// Valid Hostname specified as a proxy server
WebProxy wp = new WebProxy("my-proxy.example.com", 80);

//  Alternative:   Valid IP Address specified as the proxy server
//  WebProxy wp = new WebProxy("192.168.80.80", 80);

System.Net.WebClient client = new System.Net.WebClient();

client.Proxy = wp;
client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357:80", @"DataDetail.csv");
使用有效代理服务器的工作代码:

System.Net.WebClient wc = new System.Net.WebClient();

System.Net.WebClient client = new System.Net.WebClient();

client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357:80", @"DataDetail.csv");
System.Net.WebClient wc = new System.Net.WebClient();

// Valid Hostname specified as a proxy server
WebProxy wp = new WebProxy("my-proxy.example.com", 80);

//  Alternative:   Valid IP Address specified as the proxy server
//  WebProxy wp = new WebProxy("192.168.80.80", 80);

System.Net.WebClient client = new System.Net.WebClient();

client.Proxy = wp;
client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357:80", @"DataDetail.csv");

代理服务器的名称只能是“主机名”或IP地址

有效代理服务器名称的示例:

my proxy.example.com(主机名指定为代理服务器)

192.168.10.9(指定为代理服务器的IP地址)

报告的错误显示为
http://api...
不是WebProxy功能的有效输入

如何解决这个问题?

可以通过删除代理服务器或将代理服务器指定为主机名或IP地址来解决此问题

不使用代理服务器的工作代码:

System.Net.WebClient wc = new System.Net.WebClient();

System.Net.WebClient client = new System.Net.WebClient();

client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357:80", @"DataDetail.csv");
System.Net.WebClient wc = new System.Net.WebClient();

// Valid Hostname specified as a proxy server
WebProxy wp = new WebProxy("my-proxy.example.com", 80);

//  Alternative:   Valid IP Address specified as the proxy server
//  WebProxy wp = new WebProxy("192.168.80.80", 80);

System.Net.WebClient client = new System.Net.WebClient();

client.Proxy = wp;
client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357:80", @"DataDetail.csv");
使用有效代理服务器的工作代码:

System.Net.WebClient wc = new System.Net.WebClient();

System.Net.WebClient client = new System.Net.WebClient();

client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357:80", @"DataDetail.csv");
System.Net.WebClient wc = new System.Net.WebClient();

// Valid Hostname specified as a proxy server
WebProxy wp = new WebProxy("my-proxy.example.com", 80);

//  Alternative:   Valid IP Address specified as the proxy server
//  WebProxy wp = new WebProxy("192.168.80.80", 80);

System.Net.WebClient client = new System.Net.WebClient();

client.Proxy = wp;
client.DownloadFile("http://api-adresse.data.gouv.fr/reverse/?lon=2.37&lat=48.357:80", @"DataDetail.csv");

呃。如果我是你,我会仔细看看你的网址。这看起来不像是一个代理服务器。我只需要一个主机名。试着在配置中添加这样的一个部分-->@GauriShankarBadola-对不起,这与他的问题无关。呃。如果我是你,我会仔细看看你的网址。这看起来不像是一个代理服务器。我只需要一个主机名。请尝试在配置中添加这样的部分-->@GauriShankarBadola-抱歉,这与他的问题无关。我收到此错误[error]错误:远程服务器返回了一个错误:(407)需要代理身份验证。然后您需要一个有效的代理URL。有关示例,请参阅@Gopinath answer。我收到此错误[error]错误:远程服务器返回了一个错误:(407)需要代理身份验证。然后,您需要一个有效的代理URL。有关示例,请参见@Gopinath answer。在哪里可以找到代理?如果已为计算机设置了代理服务器,则可以在浏览器设置中找到。(对于Chrome,可以在Chrome-->设置-->代理中找到它)。在哪里找到代理?如果已经为计算机设置了代理服务器,可以在浏览器设置中找到。(对于Chrome,可在Chrome-->设置-->代理中找到)。