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

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5