Get text from website to c# application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dake123
    New Member
    • Apr 2013
    • 1

    Get text from website to c# application

    Hello, i Would like to know an easy way to let my application show in a label, some stats from a website. thanks.
  • SirZizo
    New Member
    • Apr 2013
    • 4

    #2
    this method can help you


    Code:
     public static String readFromLink(string URL)
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                request.Method = "GET";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                String data = null;
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Stream receiveStream = response.GetResponseStream();
                    StreamReader readStream = null;
                    if (response.CharacterSet == null)
                        readStream = new StreamReader(receiveStream);
                    else readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                    data = readStream.ReadToEnd(); 
                    response.Close();
                    readStream.Close();
                }
                return data;
    
               
    
    
            }
    Last edited by Rabbit; Apr 22 '13, 05:50 AM. Reason: Please use code tags when posting code.

    Comment

    Working...