Created
April 5, 2009 07:49
-
-
Save robertpi/90400 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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