/// <summary> /// 测试代理配置 /// </summary> /// <param name="setting">代理信息</param> public static bool TestProxy(ProxySettingEntity setting, TestEntity te) { if (setting == null) { return(false); } HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(te.TestUrl); WebProxy proxy = WebProxy.GetDefaultProxy(); if (setting.Ip != null && setting.Ip != "" && setting.Port != 0) { proxy.Address = new Uri("http://" + setting.Ip + ":" + setting.Port + "/"); if (!string.IsNullOrEmpty(setting.UserName) && !string.IsNullOrEmpty(setting.Password)) { proxy.Credentials = new NetworkCredential(setting.UserName, setting.Password); } } webRequest.Proxy = proxy; webRequest.Method = "Get"; webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; CIBA)"; WebResponse response = webRequest.GetResponse(); string html = GetHtmlString(response, Encoding.GetEncoding(te.TestWebEncoding)); response.Close(); if (html.Contains(te.TestWebTitle)) { return(true); } else { return(false); } }
/// <summary> /// 测试代理配置 /// </summary> /// <param name="setting">代理信息</param> public static bool TestProxy(ProxySettingEntity setting, TestEntity te) { if (setting == null) return false; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(te.TestUrl); WebProxy proxy = WebProxy.GetDefaultProxy(); if (setting.Ip != null && setting.Ip != "" && setting.Port != 0) { proxy.Address = new Uri("http://" + setting.Ip + ":" + setting.Port + "/"); if (!string.IsNullOrEmpty(setting.UserName) && !string.IsNullOrEmpty(setting.Password)) { proxy.Credentials = new NetworkCredential(setting.UserName, setting.Password); } } webRequest.Proxy = proxy; webRequest.Method = "Get"; webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; CIBA)"; WebResponse response = webRequest.GetResponse(); string html = GetHtmlString(response, Encoding.GetEncoding(te.TestWebEncoding)); response.Close(); if (html.Contains(te.TestWebTitle)) { return true; } else { return false; } }