LiveJournal Protocol
Introduction
The following information is intended for developers interested in writing their own LiveJournal clients to talk to the LiveJournal server. End users do not need to know any of this, and are probably better off not knowing it. ;)
Prerequisites
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 kinda confusing.
It's really HTTP
If you already know the HTTP protocol, this is going to be really easy. For those of you who don't know, HTTP is the protocol that web browsers talk to web servers with. For simplicity of writing the LiveJournal server, we've decided to just use HTTP as our protocol transport. This way, we can also go through proxies at schools and corporations really easily and without drawing any attention.
The Basics
Basically, sending a LiveJournal request is like this:
- Open a socket to www.livejournal.com on port 80
- Send an HTTP 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 approriate action based on the server's response.
Encoding the request
As mentioned previously, the request is sent as an HTTP POST request. Open your socket, and send a request looking like:
- Leave all values from a-z, A-Z, and 0-9 alone. These are fine.
- Convert spaces to a + sign.
- Convert everything else to %hh where hh is the hex representation of the character's ASCII value.
After you construct the big 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.
Note about line endings: Please note that the end of lines should be a carriage return (ASCII 13, 0x0D) and then a newline (ASCII 10, 0x0A). In Perl, C/C++ or Java this is "\r\n". In Basic, this is Chr(13) & Chr(10). Sending just the newline may work too, but it's generally better to send both.
Here is a typical response from the web server after sending your request:
After your hash is loaded, proceed with the logic of reporting errors if needed, as governed by the variables and logic above.
Protocol modes
Of course, knowing all the above isn't useful unless you actually know what operations the server supports....
Proxies
As a final feature, once you get that stuff working, is to implement support for HTTP proxies. This is very easy. Give the user a checkbox if they want to use a proxy or not, and if so, ask the proxy host and proxy port. Now, if they selected to use a proxy, do not connect to www.livejournal.com and port 80, but instead connect to their proxy host on whatever proxy port they specified. The rest is basically the same, except for one difference. Instead of doing:
You would do...
That's it! That line tells the proxy what host it needs to connect to in order to make the real request. The rest of the HTTP you should leave just as you did before. This should be all you need to know to make a LiveJournal client.
Need more help?
If anything is unclear, join the
lj_clients community, where all the client authors hang out.