I'm trying to connect to the twitter streaming api. At the moment I'm just trying to grab the incoming data stream, keep the connection open and write the data to the console. I can do this easily from a terminal using curl. The following code however runs, throws no errors, but outputs no text to the console...
StringBuilder sb = new StringBuilder();
// used on each read operation
byte[] buf = new byte[8192];
String domain = "http://stream.twitter.com/1/statuses/sample.json";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(domain);
request.Credentials = new NetworkCredential("user_name", "password");
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Encoding.ASCII.GetString(buf, 0, count);
// continue building the string
sb.Append(tempString);
}
}
while (count > 0); // any more data to read?
// print out page source
Console.WriteLine(sb.ToString());