I recently created a service to post updates to the Twitter account of my website (http://twinsornot.com/).
I found some codes that does that, but using the HttpWebRequest.
I decided to make it more simple by using WebClient.
Here's the Visual Basic .NET code:
Public Sub PostTwitterUpdate(ByVal userName As String, ByVal password As String, ByVal updateMessage As String)
Using wc As New WebClient
wc.Credentials = New NetworkCredential(userName, password)
ServicePointManager.Expect100Continue = False
Dim updateMessageBytes = System.Text.Encoding.UTF8.GetBytes("status=" & updateMessage) 'Use UTF8 to get it properly encoded if you use characters like ç ã etc...
wc.UploadData("http://twitter.com/statuses/update.xml", updateMessageBytes)
End Using
End Sub
And here is the C# version:
public void PostTwitterUpdate(string userName, string password, string updateMessage)
{
using (WebClient wc = new WebClient())
{
wc.Credentials = new NetworkCredential(userName, password);
ServicePointManager.Expect100Continue = false;
byte[] updateMessageBytes = System.Text.Encoding.UTF8.GetBytes("status=" + updateMessage); //Use UTF8 to get it properly encoded if you use characters like ç ã etc...
wc.UploadData("http://twitter.com/statuses/update.xml", updateMessageBytes);
}
}