Programmatically connect to a website using a free proxy server

I need to connect to a website using a proxy server. I can do this manually, for example, I can use the online proxy http://zend2.com , and then go to www.google.com . But this must be done programmatically. I know that I can use the WebProxy class, but how can I write code so that a proxy can be used?

Can anyone give me an example code snippet or something else?

thanks

+6
source share
2 answers

Understanding zend2's work, you can fill in the url like this:

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

to view google.

I C #, build url like this:

 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); 
+1
source

You can use the WebProxy class

MSDN Code

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

In your case

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

Source: https://habr.com/ru/post/916661/


All Articles