httpwebrequest web proxy

httpwebrequest web proxy

 When you are accessing internet using proxy server you must tell the client to use proxy server details.
Proxy server can be your network machine connected to Internet or any public proxy.
To know how client and server communicate with each other refer

Client server communication


A proxy server is a software installed on network server which monitors  and filters
incoming response and outgoing requests. It has IP address,  port number
and network credentials. You may require to contact your network administrator for those settings.

Lets take an e.g. of IE. Here you can see I'm browsing internet using Proxy server.



Here I told IE to use proxy server while accessing internet. Same way you can see in Google Gtalk, Yahoo chat etc.

Look at gtalk proxy screenshot.



Any requests that goes through IE or any other client needs to be configured to use proxy.

Now, I will show you how you can tell your .Net developed application to use proxy while accessing the web.

I hope you are familiar with
HttpWebRequest and HttpWebRequest  found at System.Net name-space.

you need to create an instance of WebProxy and tell HttpWebRequest object to use this proxy settings.

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(api);

WebProxy proxy = new WebProxy("192.168.1.100",3321);

// if your proxy server requires credentials to access it use below code
NetworkCredential credentials = new NetworkCredential("UserNAme","Password")

// notify your proxy instance about these credentials

proxy.Credentials = credentials; 

// now your proxy instance is ready to pass along with the request

request.Proxy = proxy;

  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(API);

        // setting up connection with web and posting vai GET method

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        // Returns httpwebresponse

           StreamReader reader = new StreamReader(response.GetResponseStream());

        // Read response stream

string strReponse = reader.ReadToEnd();

 

You can post the data from your application to other website using HTTP Postmethod or Get method

How to post data using HttpWebRequest
http://revenmerchantservices.com/post/HttpWebRequest-Post-method.aspx

How to post the data using HTTP GET Method
A very simple example which shows yahoo user online status.
http://revenmerchantservices.com/post/HttpWebRequest.aspx

 All above example uses Yahoo API to know user online status. 
   

Satalaj

Tags:

Membership ProviderAndroid WebView ExampleChange Firefox Proxy SettingsHttpWebRequest Post methodlive web trafficHow to use HttpWebRequest and HttpWebResponse.how to open a blog websiteFacebook blockedWeb Hosting ProvidersHttpWebRequest and yahooHide IP

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.