通过代理C#访问网页 [英] Accessing Webpage via proxy C#

查看:69
本文介绍了通过代理C#访问网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个通过代理服务器访问网页的应用程序,我正在使用以下代码 -

i am developing an application that accesses webpage via a proxy server, i am using the following code-

HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create("http://www.ncedc.org/cgi-bin/catalog-search2.pl");

            // Obtain the 'Proxy' of the  Default browser.  
            IWebProxy proxy = myWebRequest.Proxy;
            // Print the Proxy Url to the console.
            if (proxy != null)
            {
                Console.WriteLine("Proxy: {0}", proxy.GetProxy(myWebRequest.RequestUri));
            }
            else
            {
                Console.WriteLine("Proxy is null; no proxy will be used");
            }
            WebClient client = new System.Net.WebClient();
            NameValueCollection postData = new NameValueCollection();
            postData.Add("format", "ncread");
            postData.Add("mintime", "2013/08/03,00:00:00");
            postData.Add("minmag", "1.0");
            postData.Add("etype", "E");
            postData.Add("outputloc", "web");
            postData.Add("searchlimit", "200000");
            client.Proxy = new WebProxy("10.10.10.1",8080);
            byte[] data = client.UploadValues("http://www.ncedc.org/cgi-bin/catalog-search2.pl", "POST", postData);
            string html = System.Text.Encoding.UTF8.GetString(data);
            if (File.Exists("C:\\Windows\\Temp\\text.html"))
            {
                File.Delete("C:\\Windows\\Temp\\text.html");
            }
            File.WriteAllText("C:\\Windows\\Temp\\text.html", html);
            Console.ReadKey();

        }





抛出认证错误-407请帮助



throws authentication error-407 please help

推荐答案

尝试使用默认凭据,如图所示。



client.Proxy.Credentials = CredentialCache.DefaultCredentials;
Try with the default credentials as shown.

client.Proxy.Credentials = CredentialCache.DefaultCredentials;


这篇关于通过代理C#访问网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆