English 中文(简体)
程序上使用免费代理服务器连接到网站
原标题:connect to website using a free proxy server programmatically

我需要使用代理服务器连接到网站。 我可以手动操作, 例如, 我可以使用在线代理服务器 < code> http://zend2. com , 然后冲浪到 < code> www.google.com 。 但是这必须在程序上进行 。 我知道我可以使用 < code> WebProxy 类, 但我怎么写代码才能使用代理服务器?

有人能给我一个代码片段作为例子吗?

感谢 谢谢

最佳回答

了解 zend2 的工作, 您可以弹出像这样的 URL :

< a href=" "http://zend2.com/bro.php? u=http% 3A% 2F% 2Fwww.google.com&b=12&f=norefer" rel="nofol"? >http://zend2.com/bro.php?u=http%3A%2F%2Fwww.google.com&b=12&f=norefer

用于浏览谷歌。

#IC#, 建造这样的骨灰圈 :

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);
问题回答

您可以使用 < a href=>" "http://msdn.microsoft.com/en-us/library/system.net.webproxy.aspx" rel = "no follow" >WebProxy class

MSDN 代码

WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebRequest req = WebRequest.Create("http://www.contoso.com");
req.Proxy = proxyObject;

在你的情况下

WebProxy proxyObject = new WebProxy("http://zend2.com",true);
WebRequest req = WebRequest.Create("www.google.com");
req.Proxy = proxyObject;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签