In this tutorial I'll show you how to post new entry to LiveJournal with perl.
It's quite simple: we should open a socket and create HTTP request to send it to a LiveJournal server. First of all, we'll get current date and time:
($sec, $Gmin, $Ghour, $mday, $Gmon,
$Gyear, $wday, $yday, $isdst) = localtime;
$Gyear += 1900;
$Gmon += 1;
Then define all variables:
use IO::Socket qw(:DEFAULT :crlf);
$c = new CGI;
$year = $c->param("year");
$mon = $c->param("mon");
$day = $c->param("day");
$subject = $c->param("subject");
$hour = $c->param("hour");
$min = $c->param("min");
$event = $c->param("event");
$act = $c->param("act");
Change USER and PASSWORD for your LiveJournal username and password. Variables $subject and $event must contain subject of an entry and entry text correspondingly. Read this for more information about arguments of such HTTP request.
Note that agrument password is plain-text, so, if you worry about security, use alternative argument hpassword to send yor password as an MD5 hex digest.
Also if text of your subject and entry not in UTF-8 codepage, you should encode it with something like this:
Encode::from_to($subject, "cp1251", "utf8");
Encode::from_to($event, "cp1251", "utf8");
and add to variable $post (wich contains HTTP request) argument &ver=1.
To post in community add to variable $post argument &usejournal=CMNT with the name of community you want to post instead CMNT.
And now we're ready to make the HTTP request to LiveJournal server. Take a look at the example:
if ($act eq "post")
# open socket
my $sock = IO::Socket::INET->new(
PeerAddr => 'www.livejournal.com',
PeerPort => '80',
Proto => 'tcp'
# get the length of request
$l = length($post);
# print in socket request
print $sock join("\r\n" =>
"POST /interface/flat HTTP/1.0",
# get answer from server
That's all! To know more, read the Flat Client/Server Protocol Reference on livejournal.com.