当前位置: 首页>>代码示例>>C#>>正文


C# Net.WebProxy类代码示例

本文整理汇总了C#中System.Net.WebProxy的典型用法代码示例。如果您正苦于以下问题:C# WebProxy类的具体用法?C# WebProxy怎么用?C# WebProxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WebProxy类属于System.Net命名空间,在下文中一共展示了WebProxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadLocal

 public KeePassQiniu.KeePassQiniuExt.UploadError UploadLocal(string name, string dbfile, out string tips) {
     Init();
     System.Net.IWebProxy webProxy = null;
     if(KeePassQiniu.KeePassQiniuConfig.Default.UseProxy) {
         webProxy = new System.Net.WebProxy(KeePassQiniu.KeePassQiniuConfig.Default.ProxyUrl, true);
     }
     // bak first
     if(KeePassQiniu.KeePassQiniuConfig.Default.AutoBackup) {
         MyRSClient moveclient = new MyRSClient();
         CallRet moveret = moveclient.Move(new EntryPathPair(KeePassQiniu.KeePassQiniuConfig.Default.QiniuBucket, name, "backup_" + System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ffff") + "_" + name));
         if(!moveret.OK) {
             tips = moveret.Response;
             return KeePassQiniuExt.UploadError.AUTOBAK_ERROR;
         }
     }
     // upload
     var policy = new PutPolicy(KeePassQiniu.KeePassQiniuConfig.Default.QiniuBucket);
     string upToken = policy.Token();
     PutExtra extra = new PutExtra();
     IOClient client = new IOClient();
     client.Proxy = webProxy;
     PutRet uploadret = client.PutFile(upToken, name, dbfile, extra);
     if(!uploadret.OK) {
         tips = uploadret.Response;
         return KeePassQiniuExt.UploadError.UPLOAD_ERROR;
     }
     tips = string.Empty;
     return KeePassQiniuExt.UploadError.OK;
 }
开发者ID:Hxs1990,项目名称:KeePassQiniu,代码行数:29,代码来源:QiniuCloud.cs

示例2: XmlRpcPings

        public XmlRpcPings(string name, string url, string feedUrl, string[] pingUrls)
        {
            this.siteName = name;
            this.siteUrl = url;
            this.siteFeedUrl = feedUrl;
            this.pingServiceUrls = pingUrls;

            this.UserAgent = SiteSettings.VersionDescription;
            this.Timeout = 60000;

            // This improves compatibility with XML-RPC servers that do not fully comply with the XML-RPC specification.
            this.NonStandard = XmlRpcNonStandard.All;

            // Use a proxy server if one has been configured
            SiteSettings siteSettings = SiteSettings.Get();
            if (siteSettings.ProxyHost != string.Empty)
            {
                WebProxy proxy = new WebProxy(siteSettings.ProxyHost, siteSettings.ProxyPort);
                proxy.BypassProxyOnLocal = siteSettings.ProxyBypassOnLocal;

                if (siteSettings.ProxyUsername != string.Empty)
                    proxy.Credentials = new NetworkCredential(siteSettings.ProxyUsername, siteSettings.ProxyPassword);

                this.Proxy = proxy;
            }
        }
开发者ID:chartek,项目名称:graffiticms,代码行数:26,代码来源:XmlRpcPings.cs

示例3: SetDefaultProxy

        /// <summary>
        /// Sets the default proxy for every HTTP request.
        /// If the caller would like to know if the call throws any exception, the second parameter should be set to true
        /// </summary>
        /// <param name="settings">proxy settings.</param>
        /// <param name="throwExceptions">If set to <c>true</c> throw exceptions.</param>
        public static void SetDefaultProxy(Config.ProxySettings settings, bool throwExceptions = false)
        {
            try
            {
                IWebProxy proxy = null;
                switch(settings.Selection) {
                    case Config.ProxySelection.SYSTEM:
                        proxy = WebRequest.GetSystemWebProxy();
                        break;
                    case Config.ProxySelection.CUSTOM:
                        proxy = new WebProxy(settings.Server);
                        break;
                }

                if (settings.LoginRequired && proxy != null) {
                    proxy.Credentials = new NetworkCredential(settings.Username, Crypto.Deobfuscate(settings.ObfuscatedPassword));
                }

                WebRequest.DefaultWebProxy = proxy;
            }
            catch (Exception e)
            {
                if (throwExceptions) {
                    throw;
                }

                Logger.Warn("Failed to set the default proxy, please check your proxy config: ", e);
            }
        }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:35,代码来源:HttpProxyUtils.cs

示例4: BetfairClientSync

 public BetfairClientSync(Exchange exchange,
     string appKey,
     Action preNetworkRequest = null,
     WebProxy proxy = null)
 {
     client = new BetfairClient(exchange, appKey, preNetworkRequest, proxy);
 }
开发者ID:hugocorreia77,项目名称:betfairng,代码行数:7,代码来源:BetfairClientSync.cs

示例5: BypassArrayList

		public void BypassArrayList ()
		{
			Uri proxy1 = new Uri ("http://proxy.contoso.com");
			Uri proxy2 = new Uri ("http://proxy2.contoso.com");

			WebProxy p = new WebProxy (proxy1, true);
			p.BypassArrayList.Add ("http://proxy2.contoso.com");
			p.BypassArrayList.Add ("http://proxy2.contoso.com");
			Assert.AreEqual (2, p.BypassList.Length, "#1");
			Assert.IsTrue (!p.IsBypassed (new Uri ("http://www.google.com")), "#2");
			Assert.IsTrue (p.IsBypassed (proxy2), "#3");
			Assert.AreEqual (proxy2, p.GetProxy (proxy2), "#4");

			p.BypassArrayList.Add ("?^[email protected]#$%^&}{][");
			Assert.AreEqual (3, p.BypassList.Length, "#10");
			try {
				Assert.IsTrue (!p.IsBypassed (proxy2), "#11");
				Assert.IsTrue (!p.IsBypassed (new Uri ("http://www.x.com")), "#12");
				Assert.AreEqual (proxy1, p.GetProxy (proxy2), "#13");
				// hmm... although #11 and #13 succeeded before (#3 resp. #4), 
				// it now fails to bypass, and the IsByPassed and GetProxy 
				// methods do not fail.. so when an illegal regular 
				// expression is added through this property it's ignored. 
				// probably an ms.net bug?? :(
			} catch (ArgumentException) {
				Assert.Fail ("#15: illegal regular expression");
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:28,代码来源:WebProxyTest.cs

示例6: TryGetHTMLString

 public static String TryGetHTMLString(String username, String password, String code
     , WebProxy proxy, bool isNormal)
 {
     String resultStr = null;
     int maxTry = 3;
     while (resultStr == null && maxTry-- > 0)
     {
         try
         {
             if (isNormal)
             {
                 resultStr = GetHTMLString(username, password, code, proxy);
             }
             else
             {
                 Assembly asm = Assembly.Load("GPAToolPro");
                 Type util = asm.GetType("GPAToolPro.AdminFunctionLib");
                 Object result = util.InvokeMember("GetAdminScoreHTMLString", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod
                     , null, null, new object[] { username, XMLConfig.adminUsername, XMLConfig.adminPassword, code, proxy });
                 resultStr = (result == null && result is String) ? null : (String)result;
             }
         }
         catch
         {
             resultStr = null;
         }
     }
     return resultStr;
 }
开发者ID:hackerzhou,项目名称:GPATool,代码行数:29,代码来源:ScoreHTMLUtil.cs

示例7: GetWebProxy

        /// <summary>
        /// Computes a <see cref="IWebProxy">web proxy</see> resolver instance
        /// based on the combination of proxy-related settings in this vault
        /// configuration.
        /// </summary>
        /// <returns></returns>
        public IWebProxy GetWebProxy()
        {
            IWebProxy wp = null;

            if (UseNoProxy)
            {
                wp = GlobalProxySelection.GetEmptyWebProxy();
            }
            else if (!string.IsNullOrEmpty(ProxyUri))
            {
                var newwp = new WebProxy(ProxyUri);
                if (UseDefCred)
                {
                    newwp.UseDefaultCredentials = true;
                }
                else if (!string.IsNullOrEmpty(Username))
                {
                    var pw = PasswordEncoded;
                    if (!string.IsNullOrEmpty(pw))
                        pw = Encoding.Unicode.GetString(Convert.FromBase64String(pw));
                    newwp.Credentials = new NetworkCredential(Username, pw);
                }
            }

            return wp;
        }
开发者ID:bseddon,项目名称:ACMESharp,代码行数:32,代码来源:ProxyConfig.cs

示例8: Get

        /// <summary>
        /// Send a GET request to a web page. Returns the contents of the page.
        /// </summary>
        /// <param name="url">The address to GET.</param>
        public string Get(string url, ProxySettings settings)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            // Use a proxy
            if (settings.UseProxy)
            {
                IWebProxy proxy = request.Proxy;
                WebProxy myProxy = new WebProxy();
                Uri newUri = new Uri(settings.ProxyAddress);

                myProxy.Address = newUri;
                myProxy.Credentials = new NetworkCredential(settings.ProxyUsername, settings.ProxyPassword);
                request.Proxy = myProxy;
            }

            request.Method = "GET";
            request.CookieContainer = cookies;
            WebResponse response = request.GetResponse();
            StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
            string result = sr.ReadToEnd();
            sr.Close();
            response.Close();

            return result;
        }
开发者ID:GhostBasenji,项目名称:2pix-steganography,代码行数:30,代码来源:HTTPControl.cs

示例9: SetDefaultProxy

        public static void SetDefaultProxy(this HttpWebRequest request)
        {
            if (request != null)
            {
                // Get the config for the proxy
                bool proxyActive = false;
                bool.TryParse(WebConfigurationManager.AppSettings["Proxy.Active"], out proxyActive);

                // No need to process the rest if there is no proxy
                if (proxyActive)
                {
                    string proxyUrl = WebConfigurationManager.AppSettings["Proxy.Url"];
                    int proxyPort = 80;
                    int.TryParse(WebConfigurationManager.AppSettings["Proxy.Port"], out proxyPort);
                    string proxyUser = WebConfigurationManager.AppSettings["Proxy.Username"];
                    string proxyPassword = WebConfigurationManager.AppSettings["Proxy.Password"];
                    string proxyDomain = WebConfigurationManager.AppSettings["Proxy.Domain"];

                    WebProxy proxy = new WebProxy(proxyUrl, proxyPort);
                    if (!string.IsNullOrEmpty(proxyUser) || !string.IsNullOrEmpty(proxyPassword) || !string.IsNullOrEmpty(proxyDomain))
                        proxy.Credentials = new NetworkCredential(proxyUser, proxyPassword, proxyDomain);

                    request.Proxy = proxy;
                }
            }
        }
开发者ID:visualjazz-mwingert,项目名称:LL-FB-July-Camapaign,代码行数:26,代码来源:HttpWebRequestExtension.cs

示例10: buttonTestPorxy_Click

        private void buttonTestPorxy_Click(object sender, EventArgs e)
        {
            if (checkBoxDontUseProxy.Checked)
            {
                SaveProxyParams();
                return;
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
            request.Credentials = new NetworkCredential(textBoxUserProxy.Text, textBoxPasswordProxy.Text);

            WebProxy webProxy = new WebProxy(textBoxURLProxy.Text, true)
            {
                UseDefaultCredentials = false
            };
            webProxy.Credentials = request.Credentials;

            request.Proxy = webProxy;
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message, "Proxy authentification", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            SaveProxyParams();
            MessageBox.Show("Proxy authentification succesful", "Proxy authentification", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
开发者ID:alexey-zhulin,项目名称:dataportal,代码行数:30,代码来源:MainForm.cs

示例11: Get_Launch_Specific_Data

        public static bool Get_Launch_Specific_Data(out String user_data)
        {
            user_data = String.Empty;
            try
            {
                string sURL = "http://169.254.169.254/latest/user-data/";
                WebRequest wrGETURL;
                wrGETURL = WebRequest.Create(sURL);
                WebProxy myProxy = new WebProxy("myproxy", 80);
                myProxy.BypassProxyOnLocal = true;

                Stream objStream;
                objStream = wrGETURL.GetResponse().GetResponseStream();
                StreamReader sr = new StreamReader(objStream);
                user_data = sr.ReadToEnd();

                Console.WriteLine("user_Data_String=" + user_data);
                if (!Get_My_IP_AND_DNS(out UtilsDLL.AWS_Utils.aws_ip, out UtilsDLL.AWS_Utils.aws_dns))
                {
                    Console.WriteLine("Get_My_IP_AND_DNS() failed!!");
                    return false;
                }
                is_aws = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("Excpetion in Get_Launch_Specific_Data(). = " + e.Message);
                is_aws = false;
                return false;
            }

            return true;
        }
开发者ID:tamirez3dco,项目名称:Rendering_Code,代码行数:33,代码来源:AWS_Utils.cs

示例12: Worker

        public Worker(HttpListenerContext context)
        {
            this.context = context;

            port = ConfigurationManager.AppSettings["proxy_port"];
            host = ConfigurationManager.AppSettings["proxy_host"];

            //init proxy
            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["parent_host"]) && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["parent_port"]))
            {
                parent = new WebProxy(ConfigurationManager.AppSettings["parent_host"], int.Parse(ConfigurationManager.AppSettings["parent_port"]));

                if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["parent_user"]))
                {
                    parent.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["parent_user"], ConfigurationManager.AppSettings["parent_pass"], ConfigurationManager.AppSettings["parent_domain"]);
                }
                else
                {
                    parent.UseDefaultCredentials = true;
                }
            }
            else
            {
                parent = null;
            }
        }
开发者ID:oxyva,项目名称:SimpleProxy,代码行数:26,代码来源:Program.cs

示例13: Create

        /// <summary>
        /// Create a web request.
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="contentType"></param>
        /// <returns></returns>
        public HttpWebRequest Create(Uri uri, string contentType) {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

            if (settings.HasProxySettings) {
                NetworkCredential credentials = null;
                if (settings.HasProxyCredentials) {
                    if (!string.IsNullOrWhiteSpace(settings.ProxyDomain)) {
                        credentials = new NetworkCredential(settings.ProxyUserName, settings.ProxyPassword, settings.ProxyDomain);
                    }
                    else {
                        credentials = new NetworkCredential(settings.ProxyUserName, settings.ProxyPassword);
                    }
                }

                WebProxy proxy = null;
                if (credentials != null) {
                    proxy = new WebProxy(settings.ProxyUrl, settings.BypassProxyOnLocal, null, credentials);
                }
                else {
                    proxy = new WebProxy(settings.ProxyUrl, settings.BypassProxyOnLocal);
                }
                request.Proxy = proxy;
            }
            request.Timeout = settings.TimeoutInSeconds * 1000;
            if (contentType != null && contentType.IndexOf(";") > 0) {
                request.ContentType = contentType.Substring(0, contentType.IndexOf(";"));
            }
            else {
                request.ContentType = contentType;
            }
            request.Method = "POST";

            return request;
        }
开发者ID:OnpointOnDemand,项目名称:fluentjdf,代码行数:40,代码来源:HttpWebRequestFactory.cs

示例14: Post

        public static string Post(string url, string reference, Char[] postDataStr/*String postDataStr*/, CookieContainer myCookieContainer, bool autoRedirect, WebProxy proxy = null)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                if (proxy != null)
                    request.Proxy = proxy;
                request.Method = "POST";
                request.CookieContainer = myCookieContainer;
                request.AllowAutoRedirect = autoRedirect;
                request.ContentType = "application/x-www-form-urlencoded"; //必须要的
                request.ServicePoint.Expect100Continue = false;
                if (reference != "")
                    request.Referer = reference;

                //request.ContentLength = postDataStr.Length;
                StreamWriter writer = new StreamWriter(request.GetRequestStream());
                writer.Write(postDataStr, 0, postDataStr.Length);
                writer.Flush();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                string encoding = response.ContentEncoding;
                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
                string retStr = sr.ReadToEnd();
                sr.Close();
                return retStr;
            }
            catch (WebException ex)
            {
                return "ERROR!:"+ ex.Message.ToString();
            }
        }
开发者ID:CNNCC,项目名称:WeiboMagic,代码行数:31,代码来源:HttpHandleHelper.cs

示例15: GetToken

        public static string GetToken(string url, WebProxy proxy = null)
        {
            string webData = WebCache.Instance.GetWebData(@"http://ida.omroep.nl/npoplayer/i.js?s=" + HttpUtility.UrlEncode(url), proxy: proxy);
            string result = String.Empty;

            Match m = Regex.Match(webData, @"token\s*=\s*""(?<token>[^""]*)""");
            if (m.Success)
            {
                int first = -1;
                int second = -1;
                string token = m.Groups["token"].Value;
                for (int i = 5; i < token.Length - 4; i++)
                    if (Char.IsDigit(token[i]))
                    {
                        if (first == -1)
                            first = i;
                        else
                            if (second == -1)
                                second = i;
                    }
                if (first == -1) first = 12;
                if (second == -1) second = 13;
                char[] newToken = token.ToCharArray();
                newToken[first] = token[second];
                newToken[second] = token[first];
                return new String(newToken);
            }
            return null;
        }
开发者ID:offbyoneBB,项目名称:mp-onlinevideos2,代码行数:29,代码来源:NPOHelper.cs


注:本文中的System.Net.WebProxy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。