Capture response from server

If you need to get the response from a server without displaying it on the browser, use the HttpWebRequest and HttpWebResponse classes. Sample code is below. If you want to post data and capture the response, click
post data to server and capture response.

StringBuilder str = new StringBuilder();
byte[] buffer = new byte[8000];

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(

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

Stream stream = response.GetResponseStream();

string temp = null;
int count = 0;

count = stream.Read(buffer, 0, buffer.Length);
if(count != 0)
temp = Encoding.ASCII.GetString(buffer, 0, count);
while(count > 0);


One thought on “Capture response from server

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s