Click here to Skip to main content
15,124,646 members
Articles / Web Development
Tip/Trick
Posted 27 Feb 2012

Tagged as

Stats

11.9K views

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
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)

Share

About the Author

FrostedSyntax
Web Developer JBHworks
United States United States
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 Pin
kirahvi18-Dec-12 0:10
Memberkirahvi18-Dec-12 0:10 
GeneralReason for my vote of 3 nice and simple. Pin
Dean Oliver27-Feb-12 7:08
MemberDean Oliver27-Feb-12 7:08 
Reason for my vote of 3
nice and simple.

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.