Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Xml;

private static void PostTweet(string username, string password, string tweet)
    {
        try
        {
            // encode the username/password
            string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
            // determine what we want to upload as a status
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes("status=" + tweet);
 
            // connect with the update page
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://twitter.com/statuses/update.xml");
            // set the method to POST
            request.Method = "POST";
            request.ServicePoint.Expect100Continue = false; // thanks to argodev for this recent change!
            // set the authorisation levels
            request.Headers.Add("Authorization", "Basic " + user);
            request.ContentType = "application/x-www-form-urlencoded";
            // set the length of the content
            request.ContentLength = bytes.Length;
 
            // set up the stream
            Stream reqStream = request.GetRequestStream();
            // write to the stream
            reqStream.Write(bytes, 0, bytes.Length);
            // close the stream
            reqStream.Close();
        }
        catch (Exception ex) {/* DO NOTHING */}
    }
Posted 30-Oct-12 2:58am
Edited 30-Oct-12 3:23am
v2
Comments
joshrduncan2012 at 30-Oct-12 9:12am
   
What is your question? Please "Improve Question" with specific questions regarding what issues you are running into. We cannot help you with just your code with no questions. "Isn't working" will not be acceptable.
Anand_Pogostick at 30-Oct-12 9:29am
   
sorry!!! My problem is the code is running perfectly without any exception but the tweets are not updated in the twitter..
Guirec Le Bars at 30-Oct-12 12:14pm
   
There is really few chances your code is raising an exception with a catch{ /* DO NOTHING */}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Maciej Los 205
2 Peter Leow 140
3 Suvendu Shekhar Giri 134
4 Abhinav S 126
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 8,895
2 Peter Leow 5,044
3 Kornfeld Eliyahu Peter 3,333
4 Maciej Los 2,561


Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 30 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100