将WebClient连接到需要身份验证的代理

时间:2014-12-22 16:55:57

标签: c# proxy

我正在尝试连接到需要身份验证的私有代理(用户:传递) 和IP。

尝试测试代理是否在这里工作是我的代码,我总是在捕获:

    public static bool IsUp(string proxy, int timeout, string url = "https://www.youtube.com/")
    {
        bool isUp = true;
        WebProxy webProxy;
        //remove ssl warning
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
        if (proxy.Count(x => x == ':') >= 2)
        {
            string proxyUser = proxy.Split(new char[] { ':', ':' })[2];
            string proxyPass = proxy.Split(new char[] { ':', ' ' })[3];
            string proxyProxy = proxy.Split(new char[] { ' ', ':' })[0] + ':' + proxy.Split(new char[] { ':', ':' })[1];
            ICredentials credentials = new NetworkCredential(proxyUser, proxyPass);
            webProxy = new WebProxy(proxyProxy,true,null,credentials);
        }
        else
            webProxy = new WebProxy(proxy);
        WebClient client = new Utilities.TimeoutWebClient(timeout);
        client.Proxy = webProxy;

        try
        {
            Stream stream = client.OpenRead(url);
        }
        catch(Exception lol)
        {
            MessageBox.Show(lol.Message);
            isUp = false;
        }

        return isUp;
    }

例外是: 底层连接已关闭:接收时发生意外错误。

是因为我需要让流做一些事情吗?即使它打开了网址 仍然没有工作

0 个答案:

没有答案
相关问题