
$param=array(“user”=>”test_user”,”host”=>”example.com”,”password”=>”some_password”);
$request = xmlrpc_encode_request(‘check_password’, $param, (array(‘encoding’ => ‘utf-8′)));
$context = stream_context_create(array(‘http’ => array(
‘method’ => “POST”,
‘header’ => “Content-Type: text/xml\r\n” .
“Content-Length: “.strlen($request),
‘content’ => $request
)));
$file = file_get_contents(“http://127.0.0.1:1234/RPC2″, false, $context);
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
print_r(“error”);
} else {
print_r($response);
}
Library: xmlrpc-1.13
But this library does not support domain, only support IP address,
so do the following hacking:
send(Socket, URI, Header, Payload) ->
[Host,_URI] = URI,
Request = ["POST ", _URI, " HTTP/1.1\r\n", "Host: ", Host,"\r\n",
"Content-Length: ", integer_to_list(lists:flatlength(Payload)), "\r\n",
"User-Agent: Erlang XML-RPC Client 1.13\r\n",
"Content-Type: text/xml\r\n",
Header, "\r\n",
Payload],
gen_tcp:send(Socket, Request).
Then you can call xmlrpc as:
- xmlrpc:call("dev.test.com", 80,
- ["dev.test.com", "/services/xmlrpc"],
- {call, METHORD, [Args]}).
timestamp() ->
{Mega,Sec,Micro} = erlang:now(),
(Mega*1000000+Sec)*1000000+Micro.