Click here to Skip to main content
15,793,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)
            // 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("");
            // 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
        catch (Exception ex) {/* DO NOTHING */}
Updated 30-Oct-12 3:23am
joshrduncan2012 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 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 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)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900