×
Home About Us Products Services News Free Scripts Contact
news php scripts and software

C# (C Sharp) example - How to read a content of a web page using C# and store into a string variable?


C# (C Sharp) - How to read a content of a web page using C# and store into a string variable?

// Create a 'WebRequest' object with the specified url.
WebRequest myWebRequest = WebRequest.Create("http://zamov.online.fr");

// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse();

// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = myWebResponse.GetResponseStream();

Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

// Pipe the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( ReceiveStream, encode );

string strResponse=readStream.ReadToEnd();

Console.WriteLine(strResponse);

readStream.Close();

// Release the resources of response object.
myWebResponse.Close();

Category: C# (C Sharp)

 
<< Go back