Reading data from an open HTTP stream

前端 未结 4 603
醉梦人生
醉梦人生 2021-02-02 16:23

I am trying to use the .NET WebRequest/WebResponse classes to access the Twitter streaming API here \"http://stream.twitter.com/spritzer.json\".

I need to b

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 17:13

    Have you tried WebRequest.BeginGetRequestStream() ?

    Or something like this:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create (http://www.twitter.com );
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    StreamReader reader = new StreamReader(response.GetResponseStream()); 
    
    string str = reader.ReadLine();
    while(str != null)
    {
       Console.WriteLine(str);
       str = reader.ReadLine();
    }
    

提交回复
热议问题