Hi
Can any one tell me why used HttpResponse class and httpRequest....?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Zoran HorvatPosted Aug 5, 2011, 6:41 AM
After that you can inspect HTTP response status, headers and response body using HttpWebResponse.
Here is a sample code regarding these classes that I've written for another thread today:
using System.Net;
using System;
using System.IO;
namespace ExceptionTest
{
class Program
{
static void Main(string[] args)
{
try
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.google.com/search?hl=en&source=hp&biw=1680&bih=917&q=search+something&oq=search+something&aq=f&aqi=g7g-v3&aql=&gs_sm=e&gs_upl=2820l4595l0l4723l16l11l0l3l3l1l231l1188l2.4.2l8l0");
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
string html = null;
if (resp.StatusCode == HttpStatusCode.OK)
{
using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
html = reader.ReadToEnd();
}
Console.WriteLine(html);
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("Press ENTER to continue...");
Console.ReadLine();
}
}
}
The original thread is:
http://www.c-sharpcorner.com/Forums/Thread/135011/find-text-in-web-page.aspx
Zoran