I am trying to use public proxy server (http://www.unblockwebnow.info/) to send HTTP request to destination site, say http://stackoverflow.com :)
My HTTP client has following architecture:
string url = "http://stackoverflow.com";
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.Method = "GET";
WebProxy myProxy = new WebProxy();
myProxy.Address = new Uri("http://www.unblockwebnow.info/");
HttpWRequest.Proxy = myProxy;
HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), encoding);
var rawHTML = sr.ReadToEnd();
sr.Close();
After executing the code for rawHTML I get "pageok -managed by puppet - hostingcms02 pageok"
If I comment out HttpWRequest.Proxy = myProxy;
line, I get the site content.
A proxy server lessens network traffic by rejecting unwanted requests, forwarding requests to balance and optimize server workload, and fulfilling requests by serving data from cache rather than unnecessarily contacting the true destination server. HTTP Server has proxy server capabilities built in.
What Does HTTP Proxy Mean? An HTTP Proxy serves two intermediary roles as an HTTP Client and an HTTP Server for security, management, and caching functionality. The HTTP Proxy routes HTTP Client requests from a Web browser to the Internet, while supporting the caching of Internet data.
A proxy server acts as a gateway between users and the internet and prevents access to anyone outside the network. Regular internet access via a web browser enables users to connect directly with websites. But a proxy acts as an intermediary, which communicates with webpages on users' behalf.
This seems to work, but not with your proxy (don't know port number for unblockwebnow.info). Added port number after ":" in URI
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string url = "http://stackoverflow.com";
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.Method = "GET";
WebProxy myProxy = new WebProxy();
//United States proxy, from http://www.hidemyass.com/proxy-list/
myProxy.Address = new Uri("http://72.64.146.136:8080");
HttpWRequest.Proxy = myProxy;
HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), true);
var rawHTML = sr.ReadToEnd();
sr.Close();
Console.Out.WriteLine(rawHTML);
Console.ReadKey();
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With