Created
May 26, 2010 15:25
-
-
Save snarkyboojum/414632 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
#!/usr/bin/perl6 | |
use v6; | |
my $hostname = 'identi.ca'; | |
my $port = 80; | |
my $client-name = 'perl6awesomedent'; | |
my $message = @*ARGS[0]; | |
# base64 encoded username:password - cheating :) | |
my $digest='dXNlcm5hbWU6cGFzc3dvcmQ='; | |
# should be properly URL encoded | |
my $post-data = "source=$client-name&status=$message".subst('+','%2B').subst('#','').subst(':','%3A').subst('|','%23')subst(' ','+'); | |
my $message-length = $post-data.bytes; | |
say "Denting \"$message\"..."; | |
try { | |
my IO::Socket::INET $socket .= new; | |
$socket.open($hostname, $port); | |
$socket.send("POST /api/statuses/update.xml HTTP/1.1\r\n"); | |
$socket.send("Host: $hostname\r\n"); | |
$socket.send("User-Agent: $client-name\r\n"); | |
$socket.send("Authorization: Basic $digest\r\n"); | |
$socket.send("Content-Type: application/x-www-form-urlencoded\r\n"); | |
$socket.send("Content-Length: $message-length\r\n\n"); | |
$socket.send("$post-data\r\n"); | |
my $result = $socket.recv(); | |
$socket.close(); | |
say $result; | |
CATCH { warn "Eek: $!" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment