[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] phpgroupware test_xmlrpc.php,NONE,1.1.2.1
From: |
Dan Kuykendall <address@hidden> |
Subject: |
[Phpgroupware-cvs] phpgroupware test_xmlrpc.php,NONE,1.1.2.1 |
Date: |
Tue, 28 Oct 2003 10:09:40 +0000 |
Update of /cvsroot/phpgroupware/phpgroupware
In directory subversions:/tmp/cvs-serv14571
Added Files:
Tag: proposal-branch
test_xmlrpc.php
Log Message:
added sample client, and tested out things, fixed a couple bugs. still have
more to do... as always
--- NEW FILE: test_xmlrpc.php ---
<?php
/**************************************************************************\
* The first request logs the user in and grabs the sessionid *
\**************************************************************************/
$params = array('admin', 'temppass');
$method = "api.base.login";
$data = xmlrpc_encode_request($method,$params);
$login_request = $data;
$site = 'localhost';
$location = '/demo/xmlrpc.php';
if (!($conn=fsockopen($site,81,$errno,$errstr))) exit($errstr);
else {
$headers =
"POST $location HTTP/1.0\r\n" .
"Host: $site\r\n" .
"Connection: close\r\n" .
($user_agent ? "User-Agent: $user_agent\r\n" : '') .
"Content-Type: text/xml\r\n" .
"Content-Length: " . strlen($data) . "\r\n\r\n";
fputs($conn, $headers);
fputs($conn, $data);
$response = "";
while(!feof($conn)){
$response .= fgets($conn, 1024);
}
fclose($conn);
}
$tmp = explode ("\n", $response);
$num = count($tmp);
$hit_start = False;
$result = '';
for ($i=0; $i < $num; $i++)
{
if($hit_start)
{
$result .= $tmp[$i]."\n";
}
elseif(stristr($tmp[$i], '<?xml'))
{
$hit_start = True;
$result .= $tmp[$i]."\n";
}
}
$login_result = $result;
$result = xmlrpc_decode_request ($result, $method);
$sid = $result->scalar;
xmlrpc_set_type($sid, "base64");
/**************************************************************************\
* I got the sessionid, so now I just make whatever request I want *
* The sessionid needs to be the first param I pass. *
\**************************************************************************/
$params = array($sid, 'Dan', 'Kuykendall');
$method = "api.base.start";
$data = xmlrpc_encode_request($method,$params);
$next_request = $data;
if (!($conn=fsockopen($site,81,$errno,$errstr))) exit($errstr);
else {
$headers =
"POST $location HTTP/1.0\r\n" .
"Host: $site\r\n" .
"Connection: close\r\n" .
($user_agent ? "User-Agent: $user_agent\r\n" : '') .
"Content-Type: text/xml\r\n" .
"Content-Length: " . strlen($data) . "\r\n\r\n";
fputs($conn, $headers);
fputs($conn, $data);
$response = "";
while(!feof($conn)){
$response .= fgets($conn, 1024);
}
fclose($conn);
}
$tmp = explode ("\n", $response);
$num = count($tmp);
$hit_start = False;
$result = '';
for ($i=0; $i < $num; $i++)
{
if($hit_start)
{
$result .= $tmp[$i]."\n";
}
elseif(stristr($tmp[$i], '<?xml'))
{
$hit_start = True;
$result .= $tmp[$i]."\n";
}
}
$next_result = $result;
?>
<html>
<body>
<h1>This examples the xmlrpc support of the new framework</h1>
The login request
<hr>
<pre><?php echo htmlentities($login_request);?></pre>
<hr>
The login result gives me the session id to use from now on.
<hr>
<pre><?php echo htmlentities($login_result);?></pre>
<hr>
Now that I have a valid session to work with, I will make a simple
request to the api.base.start function and send it some params to make sure Im
getting the results properly.<br>
Notice that the first param I must pass is the sessionid.
<hr>
<pre><?php echo htmlentities($next_request);?></pre>
<hr>
Here are the final results!.
<hr>
<pre><?php echo htmlentities($next_result);?></pre>
<hr>
Here is the result after its converted to php vars. I use print_r() to
display this.
<hr>
<pre>
<?php
$result = xmlrpc_decode_request ($result, $method);
print_r($result);
?>
</pre>
<hr>
</body>
</html>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] phpgroupware test_xmlrpc.php,NONE,1.1.2.1,
Dan Kuykendall <address@hidden> <=