以编程方式使用免费代理服务器连接到网站

Ozk*_*kan 6 .net c# asp.net proxy

我需要使用代理服务器连接到网站.我可以手动执行此操作,例如我可以使用在线代理http://zend2.com,然后浏览www.google.com.但这必须以编程方式完成.我知道我可以使用WebProxy类但是如何编写代码以便可以使用代理服务器?

任何人都可以给我一个代码片段作为示例或什么?

谢谢

Ste*_*e B 2

了解 zend2 的工作原理,您可以像这样填充 url:

http://zend2.com/bro.php?u=http%3A%2F%2Fwww.google.com&b=12&f=norefer

用于浏览谷歌。

IC#,像这样构建 url:

string targetUrl = "http://www.google.com";
string proxyUrlFormat = "http://zend2.com/bro.php?u={0}&b=12&f=norefer";
string actualUrl = string.Format(proxyUrlFormat, HttpUtility.UrlEncode(targetUrl));

// Do something with the proxy-ed url
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(actualUrl));
HttpWebResponse resp = req.GetResponse();

string content = null;
using(StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
    content = sr.ReadToEnd();
}

Console.WriteLine(content);
Run Code Online (Sandbox Code Playgroud)