Mono/C# returns 401 when trying to fetch data using GET

7 views
Skip to first unread message

modu...@gmail.com

unread,
Mar 7, 2008, 7:56:51 AM3/7/08
to Twitter Development Talk
Here's my simple code for connecting to Twitter with supplied
credentials:
void dologin(string username, string password){
try{
string myURL = "http://"+username+":"+password+"@twitter.com/
statuses/user_timeline.xml";
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(myURL);
HttpWebResponse hwrsp = (HttpWebResponse)hwr.GetResponse();
StreamReader sr = new StreamReader(hwrsp.GetResponseStream());
Console.WriteLine(sr.ReadToEnd());
sr.Close();
}
catch(Exception e){
Console.WriteLine(e.ToString());
}
}
When the connection is tried, the following error is returned:
System.Net.WebException: The remote server returned an error: (401)
Unauthorized.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult
asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at UserUi.dologin(String username, String password)

When I request http://twitter.com/statuses/user_timeline/user.xml, the
proper output is given, even though no authentication has occurred.
What's going on?

Mod
Reply all
Reply to author
Forward
0 new messages