Click here to Skip to main content
15,867,704 members
Articles / Web Development
Tip/Trick

Method for Making a Simple Web Request

Rate me:
Please Sign up or sign in to vote.
4.00/5 (6 votes)
26 Feb 2012CPOL 13K   2
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:
C#
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();
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer JBHworks
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
kirahvi17-Dec-12 23:10
kirahvi17-Dec-12 23:10 
GeneralReason for my vote of 3 nice and simple. Pin
Dean Oliver27-Feb-12 6:08
Dean Oliver27-Feb-12 6:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.