Before reading this document, it is assumed you know at least some basics about network programming, at least the whole idea of opening sockets and reading/writing to them. If not, this might be kind've confusing.
If you ever have any questions about building clients for LiveJournal, then
you'll probably be interested in the lj_dev community on
The archives of the lj_clients community may also be of interest.
Basically, sending a LiveJournal request is like this:
Procedure 23.1. Handshake
Open a socket to
www.livejournal.com on port 80
POST request, containing the request variables (mode, user, password, etc…)
Read the socket to get the response. The response is really easy to parse.
Close the socket. Do any appropriate action based on the server's response.
For example, your client would output a request:
POST /interface/flat HTTP/1.1 Host: www.livejournal.com Content-type: application/x-www-form-urlencoded Content-length: 34 mode=login&user=test&password=test
All values must be quoted or the values can interfere with the encoding form. For example, if somebody's password was “blah&=2+&something=yeah”, it could quite possibly ruin the encoding format. Here are some guidelines on how to encode values:
Leave all values from a-z, A-Z, and 0-9 alone. These are fine.
Convert spaces to a + (plus) sign.
Convert everything else to %
hh is the hex representation of the character's ASCII value.
For example, the phrase “I'm going to the mall” could encoded as “I%27m+going+to+the+mall”. There should be CGI libraries for all major languages which do this encoding for you. If not, it isn't that hard to do it yourself.
After you construct the long ugly string of variables/values, find the length of it and send it in the Content-length field, as in the example above. Then send a blank line, then the big long ugly string.
Please note that the end of lines should be a carriage return
0x0D) and then a
In Perl, C/C++ or Java this is “\r\n”.
In Basic, this is
Sending just the newline may work too, but it's generally better to send both.
A typical response would be:
HTTP/1.1 200 OK Date: Sat, 23 Oct 1999 21:32:35 GMT Server: Apache/1.3.4 (Unix) Connection: close Content-Type: text/plain name Mr. Test Account success OK message Hello Test Account!
The top stuff is headers from the
There may be a lot of other stuff in there too.
First thing to do is make sure the first line ends with “
If the first line does not end with “
tell the user that an error occurred on the server and that it's not their fault.
If you see “
200 OK” at the end, proceed with parsing the output.
The format is as follows:
variable value someothervariable someothervalue
The ordering of the variable/value pairs does not matter. As you read them in, read them into a hash structure (associative array, dictionary, collection…whatever it's called in your language. Just a data structure that links one string variable key to another string variable value.).
After your hash is loaded, proceed with the logic of reporting errors if needed, as governed by the variables and logic above.