I'm putting together an application with a Campfire chat feature. Most everything is working, like listing rooms and joining them. The problem I'm having is with streaming the live.json for our chatroom to a multiline textbox.
Every attempt I've made to do this returns a 401 Unauthorized error. If I use curl to confirm that it works and that my token is valid (curl -u [API TOKEN HERE]:X -v -N https://streaming.campfirenow.com/room/[ROOM NUMBER HERE]/live.json) then it works fine and begins streaming anything from the room into the console. I've even tried joining the room first in a different method and receive a 200 OK response with no issues, but even after that method is called, the stream method returns a 401 Unauthorized.
Here's my code so far:
private void streamRoom()
{
try
{
WebRequest request = WebRequest.Create("https://streaming.campfirenow.com/room/[ROOM_NUMBER]/live.json");
request.Credentials = new NetworkCredential(myToken,"X");
request.Method = "GET";
//request.ContentType = "application/json";
string serverReply = string.Empty;
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
StreamReader sr = new StreamReader(response.GetResponseStream());
serverReply = sr.ReadToEnd();
sr.Close();
response.GetResponseStream().Close();
convoBox.Text += ((HttpWebResponse)response).StatusDescription.ToString();
}
}
convoBox.Text += serverReply.ToString();
convoBox.Text += responseString;
}
catch (WebException wEx)
{
Console.WriteLine(wEx.Message.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
Now if it's not apparent from my code, I'm not exactly an expert. I'm sure there's something I'm doing wrong, since curl has no trouble. I'm sure there are other issues with this method, but I'm stuck at the auth issue so I haven't had a chance to debug anything else. That's where you actual experts come in to help slap me upside the head with some knowledge so I can hopefully move beyond this.
Thank you for your time!