Click here to Skip to main content
13,006,319 members (59,072 online)
Rate this:
Please Sign up or sign in to vote.
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 */}
Posted 30-Oct-12 1:58am
Updated 30-Oct-12 2: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 Le Bars 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170628.1 | Last Updated 30 Oct 2012
Copyright © CodeProject, 1999-2017
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