Tuesday, January 27, 2009

Request webservices in drupal 6



1. Following is the xml format for sending the request

$xmlrequest= "<?xml version='1.0'?>
<methodCall>
  <methodName>myservices.test</methodName>
    <params>
      <param>
        <value>
          <string></string>
          <int></int>
        </value>
      </param>
    </params>
  </methodCall>";

$ch = curl_init('http://localhost/drupal/services/xmlrpc');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $xmlrequest);
$result = curl_exec ($ch);
echo $result;
curl_close ($ch);

Save the file and execute in the web browser.
Note:
2. methodname will be the name of method in your service.
3. If you want to pass parameters then send it in following format

You should always maintain the order, as the values will be read in same order at the server side.

No comments: