?

Log in

No account? Create an account
Extremely new to this. - LiveJournal Client Discussions [entries|archive|friends|userinfo]
LiveJournal Client Discussions

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Extremely new to this. [Sep. 25th, 2004|07:39 pm]
LiveJournal Client Discussions

lj_clients

[4abudabit]
So I just started trying to use XML-RPC with LJ today, and this also will be my first time using sockets. My website is PHP based. Anyways, I coded this crappy little attempt to post a message but it doesn't work (which I expected). Could someone help me get started? Here is what I came up with:



$xmlrpc_message = "[?xml version='1.0'?]\n
[methodCall]\n
[methodName]LJ.XMLRPC.postevent[/methodName]\n
[params]\n
[param]\n
\n
[value][struct]\n
[member][name]4abudabit[/name]\n
[value][string]test[/string][/value]\n
[/member]\n
[member][name]password[/name]\n
\n
[value][string]test[/string][/value]\n
[/member]\n
[member][name]event[/name]\n
[value][string]This is a test post.\n
[/string][/value]\n
\n
[/member]\n
[member][name]subject[/name]\n
[value][string]Test[/string][/value]\n
[/member]\n
[member][name]lineendings[/name]\n

[value][string]pc[/string][/value]\n
[/member]\n
[member][name]year[/name]\n
[value][int]2002[/int][/value]\n
\n
[/member]\n
[member][name]mon[/name]\n
[value][int]7[/int][/value]\n
[/member]\n
[member][name]day[/name]\n
\n
[value][int]13[/int][/value]\n
[/member]\n
[member][name]hour[/name]\n
[value][int]20[/int][/value]\n
\n
[/member]\n
[member][name]min[/name]\n
[value][int]35[/int][/value]\n
[/member]\n
[/struct][/value]\n
\n
[/param]\n
[/params]\n
[/methodCall]";

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (socket_connect($socket, "66.150.15.140", 80)) echo "Socket connected?[BR]";


$len = strlen($xmlrpc_message);
$reply = socket_send($socket, $xmlrpc_message, $len, 0x100);
echo $reply;
socket_close($socket);

_______________________

All the ['s are of course greater and less than signs in the real code. What are some of the many problems with this attempt? Thank you.
linkReply

Comments:
From: perplexes
2004-09-26 01:27 am (UTC)
It would be great if you could replace all of your <'s and >'s with &lt; and &gt; respectively. :)
(Reply) (Thread)
[User Picture]From: xb95
2004-09-26 01:53 am (UTC)
Well, you have to send an HTTP header, and then the message body...
(Reply) (Thread)
[User Picture]From: 4abudabit
2004-09-26 10:16 am (UTC)
Cool, thanks!

Anyways I've fixed up my content but it still doesn't seem to be correct:

$xmlrpc_message1 = "POST / HTTP/1.0\n
User-Agent: AtomicDen Test Client\n
Host: www.livejournal.com\n
Content-Type: text/xml\n
Content-Length: 576\n
\n
[?xml version='1.0'?]\n
[methodCall]\n
[methodName]LJ.XMLRPC.login[/methodName]\n
[params]\n
[param]\n
\n
[value][struct]\n
[member][name]username[/name]\n
[value][string]4abudabit[/string][/value]\n
[/member]\n
[member][name]password[/name]\n
\n
[value][string]MYPASSWORD[/string][/value]\n
[/member]\n
[member][name]ver[/name]\n
[value][int]1[/int][/value]\n
\n
[/member]\n
[/struct][/value]\n
[/param]\n
[/params]\n
[/methodCall]";

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (socket_connect($socket, "66.150.15.140", 80)) echo "Socket connected.[BR]";


$len = strlen($xmlrpc_message1);
$length = socket_send($socket, $xmlrpc_message1, $len, 0x100);
echo $length;
$reply = socket_read($socket, 1000);
echo $reply, "[BR]_______[BR]";
socket_close($socket);

_____________________

I get a 405 Method Not Allowed message.
The requested method POST is not allowed for the URL /index.html.

Apache/1.3.31 Server at bradfitz.com Port 80
(Reply) (Parent) (Thread)
[User Picture]From: hyuri
2004-09-26 11:02 am (UTC)
You need to POST to /interface/xmlrpc, not /. Also, you don’t need to add \n if you have a literal linebreak in the string.

That’s also not the IP address for livejournal.com, it’s the IP for bradfitz.com—which doesn’t, so far as I know, have an XML‑RPC interface, much less one that can/will access LJ’s user database.
(Reply) (Parent) (Thread)
[User Picture]From: 4abudabit
2004-09-26 04:25 pm (UTC)
Thank you so much for the help. :J) I don't get the error response any more. Although now it takes about 60 for my test script to complete and it doesn't return anything from the server. It does give me the length of the data sent though so I know it was successfully sent.

$xmlrpc_message3 = 'POST /interface/xmlrpc HTTP/1.0
User-Agent: AtomicDen Test Client
Host: www.livejournal.com
Content-Type: text/xml
Content-Length: 193

[?xml version="1.0"?]
[methodCall]
[methodName]LJ.XMLRPC.getchallenge[/methodName]
[params]
[param]

[/param]
[/params]
[/methodCall]';

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (socket_connect($socket, "66.150.15.150", 80)) echo "Socket connected?[BR]";

$len = strlen($xmlrpc_message3);
$length = socket_write($socket, $xmlrpc_message3, $len);
echo $length;
$reply = socket_read($socket, 1000);
echo $reply, "[BR]_______[BR]";
echo $reply-]fullname;
socket_close($socket);
(Reply) (Parent) (Thread)
[User Picture]From: hyuri
2004-09-26 05:39 pm (UTC)
The Content-Length headers in the examples are quite inaccurate. Assuming that you’re using Windows line‑endings (\r\n, 2 characters), the actual Content-Length value is 141.

Also, despite what the CSP docs show, an empty param element is incorrect here and must be removed, reducing the Content-Length to 119—and since getchallenge has no params, the params element can be disposed of as well, leaving the following:
$xmlrpc_message3 = 'POST /interface/xmlrpc HTTP/1.0
User-Agent: AtomicDen Test Client
Host: www.livejournal.com
Content-Type: text/xml
Content-Length: 99

<?xml version="1.0"?>
<methodCall>
<methodName>LJ.XMLRPC.getchallenge</methodName>
</methodCall>';

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (socket_connect($socket, "66.150.15.150", 80)) echo "Socket connected?<BR>";

$len = strlen($xmlrpc_message3);
$length = socket_write($socket, $xmlrpc_message3, $len);
echo $length;
$reply = socket_read($socket, 1000);
echo $reply, "<BR>_______<BR>";
echo $reply->fullname;
socket_close($socket);

As a final note: you should be using test.livejournal.org as your test server, not www.livejournal.com.
(Reply) (Parent) (Thread)
[User Picture]From: 4abudabit
2004-09-26 09:32 pm (UTC)
It worked!!!!

Thank you thank you thank you thank you. You've probably saved me from at least a couple days of work and at least 4 headaches. :J)
(Reply) (Parent) (Thread)
[User Picture]From: 4abudabit
2004-09-27 08:58 pm (UTC)
I thought I had it figured out, but when I try login I don't get a response either:

POST /interface/xmlrpc HTTP/1.0
User-Agent: AtomicDen Test Client 1.0
Host: test.livejournal.org
Content-Type: text/xml
Content-Length: 405

[?xml version="1.0"?]
[methodCall]
[methodName]LJ.XMLRPC.login[/methodName]
[params]
[param]

[value][struct]
[member][name]username[/name]
[value][string]4abudabit[/string][/value]
[/member]

[member][name]password[/name]
[value][string]MYPASS[/string][/value]
[/member]
[member][name]ver[/name]
[value][int]0[/int][/value]
[/member]
[/struct][/value]
[/param]
[/params]
[/methodCall]
(Reply) (Parent) (Thread)
[User Picture]From: ilay
2004-09-29 08:37 am (UTC)
You must send HTTP-header before send XML. It wrote in documentation.

I used XML-RPC PEAR Package for working with LJ from PHP-scripts.
(Reply) (Thread)