Skip to content

Instantly share code, notes, and snippets.

@robertpi
Created April 5, 2009 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertpi/90400 to your computer and use it in GitHub Desktop.
Save robertpi/90400 to your computer and use it in GitHub Desktop.
#light
// ported from the C#: http://www.dreamincode.net/code/snippet2556.htm
open System
open System.Net
open System.Text
let postTweet username password tweet =
let user = Convert.ToBase64String(Encoding.UTF8.GetBytes(username + ":" + password))
// determine what we want to upload as a status
let bytes = Encoding.ASCII.GetBytes("status=" + tweet)
// connect with the update page
let request = WebRequest.Create("http://twitter.com/statuses/update.xml",
Method = "POST",
ContentLength = Convert.ToInt64(bytes.Length),
ContentType = "application/x-www-form-urlencoded") :?> HttpWebRequest
request.ServicePoint.Expect100Continue <- false
// set the authorisation levels
request.Headers.Add("Authorization", "Basic " + user)
// set up the stream
use reqStream = request.GetRequestStream()
reqStream.Write(bytes, 0, bytes.Length)
reqStream.Close()
postTweet "you" "xxx" "Test tweet from F# interactive"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment