1: public static class Twitter
2: {
3: public static string Post(string Status, string UserName, string Password)
4: {
5: string URL = "http://twitter.com/statuses/update.xml";
6: string Data = "status=" + HttpUtility.UrlEncode(Status);
7:
8: HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL);
9: if (!(string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password)))
10: {
11: Request.Credentials = new NetworkCredential(UserName, Password);
12: Request.ContentType = "application/x-www-form-urlencoded";
13: Request.Method = "POST";
14: Request.ServicePoint.Expect100Continue = false;
15: byte[] Bytes = Encoding.UTF8.GetBytes(Data);
16:
17: Request.ContentLength = Bytes.Length;
18: using (Stream RequestStream = Request.GetRequestStream())
19: {
20: RequestStream.Write(Bytes, 0, Bytes.Length);
21: using (WebResponse Response = Request.GetResponse())
22: {
23: using (StreamReader Reader = new StreamReader(Response.GetResponseStream()))
24: {
25: return Reader.ReadToEnd();
26: }
27: }
28: }
29: }
30: return "";
31: }
32: }