65.9K
CodeProject is changing. Read more.
Home

Method for Making a Simple Web Request

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (6 votes)

Feb 27, 2012

CPOL
viewsIcon

13818

A method for getting the response from a web request made to the specified URL.

A method for getting the response from a web request made to the specified URL:
public static string makeWebRequest(string host)
{
    var request = (HttpWebRequest)WebRequest.Create(new Uri(host));

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

    Stream dataStream = response.GetResponseStream();
    StreamReader dataread = new StreamReader(dataStream);
    return dataread.ReadToEnd();
}