【发布时间】:2013-12-20 14:50:58
【问题描述】:
我目前正在使用我的输入文本框制作代理检查器。我收到 C# 错误:索引超出了 proxy(123.34.123.45:8080) 的数组范围。
我的代码将是...
string occoultProxy = "123.34.123.45:8080";
WebProxy proxy = new WebProxy(occoultProxy.Split(':')[0], Convert.ToInt32(occoultProxy.Split(':')[1])); //Error at this line
// WebProxy(string Host, int Port)
更新
我尝试了其他代码,但仍然有错误代码。请帮忙。
string[] address = occoultProxy.Split(new[] { ':' });
MessageBox.Show(address[0].ToString());
MessageBox.Show(address[1].ToString());
WebProxy proxyHTTP = new WebProxy(address[0], Convert.ToInt32(address[1]));
输出
123.34.345.23 <!-- Some Proxy here, seems good here -->
IndexOutOfRangeException was unhandled( Index was outside the bounds of the array.)
【问题讨论】:
-
它对我有用。获取 occoultProxy 是否有问题?
-
我猜
occoultProxy的值是一个没有端口号的IP。 -
我已经尝试过您的示例,并且运行没有问题。你确定你传递给语句的字符串总是包含分号吗?因为您让用户输入地址,所以您应该检查字符串中的分号。
标签: c#