You are here: xml-rpc webserver « PHP Programming Language « IT news, forums, messages
xml-rpc webserver

Posted by Ward Germonprι on 01/23/07 15:21

Been banging my head on this all day, so here's the stoopid question:

Do we *really need* the xml-rpc extension to create a xmlrpc
webservice ?

I'm getting the impression that we're supposed to generate the XML by hand.
That's why PHP 5.1.2 has DOM methods as well as an xmlwriter class.

And invoking the webserver "function/class" can be done by general PHP code
as well, no need for *registering the method with the server* ?

Many webauthors urge us to precede any xml output with : header('Content-
Type: text/xml');

So if we have to do all that ourselves, what work does the xml-rpc
extension actually do ?




Below is my first webservice effort, using POST.

The js-client sends "Kilroy", and the webservice appends ' was here'.
I'm receiving an XML object all right, but it appears empty.

Any help appreciated...

regards
Ward



//save this as server.php
<?php
function stick($method, $param) {
return ("$param was here !");
}
$server = xmlrpc_server_create();
$rawpost=$HTTP_RAW_POST_DATA;
xmlrpc_server_register_method($server, "glue", "stick");
$xmlresponse= xmlrpc_server_call_method($server, $rawpost, '');
header('Content-Type: text/xml');
echo $xmlresponse;
?>





//save this as client.html (most of the code courtesy of PPK)
<html>
<script>
var XMLHttpFactories = [
function () {return new XMLHttpRequest()},
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
function () {return new ActiveXObject("Msxml3.XMLHTTP")},
function () {return new ActiveXObject("Microsoft.XMLHTTP")},
];

function dspobjprop(obj) {
var props="";
for (var prop in obj) {props+=prop+'='+obj[prop]+'\n';}
alert (props);
}
function createXMLHTTPObject() {
var xmlhttp = false;
for (var i=0;i<XMLHttpFactories.length;i++)
{
try {
xmlhttp = XMLHttpFactories[i]();
}
catch (e) {
continue;
}
break;
}
return xmlhttp;
}

function sendRequest(url,callback, postData) {
var req = createXMLHTTPObject();
if (!req) return;
var method = (postData) ? "POST" : "GET";
req.open(method,url,true);
req.setRequestHeader('User-Agent','XMLHTTP/1.0');
if (postData)
req.setRequestHeader('Content-type','application/x-www-form-
urlencoded');
req.onreadystatechange = function () {
if (req.readyState != 4) return;
if (req.status != 200 && req.status != 304) {

alert('HTTP error ' + req.status);
return;
}
callback(req);
}
if (req.readyState == 4) return;
req.send(data);
}

function handleResponse(req){
var returnXML=req.responseXML;
alert(returnXML);
document.innerHTML=returnXML;
alert(returnXML.getElementsByTagName('rawpost')
[0].firstChild.nodeValue);
}


var data="Kilroy";
sendRequest('server.php', handleResponse, 'POST');


</script>
</html>

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация