我需要使用代理服务器连接到网站。 我可以手动操作, 例如, 我可以使用在线代理服务器 < code> http://zend2. com , 然后冲浪到 < code> www.google.com 。 但是这必须在程序上进行 。 我知道我可以使用 < code> WebProxy 类, 但我怎么写代码才能使用代理服务器?
有人能给我一个代码片段作为例子吗?
感谢 谢谢
我需要使用代理服务器连接到网站。 我可以手动操作, 例如, 我可以使用在线代理服务器 < 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;
In my webpages I have references to js and images as such: "../../Content/Images/"Filename" In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename" 1-...
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. ...
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 ...
I m looking for best practices here. Sorry. I know it s subjective, but there are a lot of smart people here, so there ought to be some "very good" ways of doing this. I have a custom object called ...
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 ...
i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...
For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?
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!