Posted by joshon on March 5, 2011 at 6:16am
I have setup an endpoint called api.
It uses an xmlrpc server.
I have enabled system.connect in the resources tab.
I send this request:
POST http://mydomain.local/api HTTP/1.1
Accept: text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, text/css, image/png, image/jpeg, image/gif;q=0.8, application/x-shockwave-flash, video/mp4;q=0.9, flv-application/octet-stream;q=0.8, video/x-flv;q=0.7, audio/mp4, application/futuresplash, /;q=0.5
x-flash-version: 10,2,152,26
Content-Type: application/x-www-form-urlencoded
Content-Length: 102
User-Agent: Shockwave Flash
Host: mydomain.local
Pragma: no-cache
Cookie: SESSdce96b2191ab3bf38d2c87cf563b1f7d=t2cn1v5pg1rd7d9ptlpr89kpk4
<methodCall>
<methodName>system.connect</methodName>
<ignoreWhite>true</ignoreWhite>
</methodCall>And I get this response:
HTTP/1.1 200 OK
Date: Sat, 05 Mar 2011 05:25:18 GMT
Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.1
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Sat, 05 Mar 2011 05:25:18 GMT
Cache-Control: store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Connection: close
Content-Length: 378
Content-Type: text/xml
<?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>-32601</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Server error. Requested method system.connect not specified.</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>How should I correctly address system.connect ?
Comments
Is it 6.x or 7.x ?
Do you have problems with Drupal 6 or Drupal 7 ?
In 7.x version it should work, but I am not sure about 6.x as there is prefixing for xmlrpc. So please try system.xmlrpc_connect. But I think we will remove prefixing like it was done in 7.x version of Services.
It is 6.x
Sorry I didn't mention that it was 6.x!
I abandoned it for now and went back to version 2.44.
I noticed that in the resources UI - the connect method was buried in a box labeled actions.
I tried system.actions.connect (desperate!) which didn't work - but it did make me think it was a scope issue that I didn't understand.
I did succeed in calling other methods - so it was working in principle - I just couldn't get system.connect to work - which was the core of the matter unfortunately.
i gave up on 3.x in d6 too. i
i gave up on 3.x in d6 too. i noticed in the cache it's not giving me the right method name. been trying to make it work in 3.x for hours while in 2.x i got it enabled for a few minutes.
XMLRPC is very difficult and
XMLRPC is very difficult and might be broken for awhile in 6.x, Why not use something much simpler like REST?
I use mimic library
I use mimic library (http://mimic-xmlrpc.sourceforge.net/) for testing XMLRPC in services. Works pretty fine and easy for me. So what you need to do with it:
<script src="mimic.js"></script>
var request = new XmlRpcRequest("/{your site folder}/api", 'services_test.test'); request.addParam('1'); var response = request.send(); alert(response.parseXML());I assumed that http://localhost/{your site folder}/api is your XMLRPC endpoint.
Also xmlrpc function could be
Also xmlrpc function could be run for testing in devel/php, see example:
$result = xmlrpc($url, array('services_test.test' => array('1'),
));
dpm($result);
Here is a code snippet that
Here is a code snippet that logs in and creates test node:
$result = xmlrpc($url, array('user.login' => array($login, $password),
));
$options['headers']['Cookie'] = $result['session_name']. '=' . $result['sessid'];
$data=array('type'=>'page', 'title'=>'Test', 'body'=>'test');
$result = xmlrpc($url, array(
'node.create' => array($data),
), $options);
Well, here is a code that
Well, here is a code that logs in, posts request to the test service and logs out.
<?php
$url = 'http://localhost/drupal/drupal7/api';
$login = 'admin';
$password = 'admin';
// Login to the remote website via XML RPC
$result = xmlrpc($url, array(
'user.login' => array($login, $password),
));
// Save session
$options['headers']['Cookie'] = $result['session_name']. '=' . $result['sessid'];
// Get new sid
$result = xmlrpc($url, array(
'services_test.test' => array(1),
), $options);
dpm($result);
// Log out
$result = xmlrpc($url, array(
'user.logout' => array(),
), $options);
?>
thanks !
It looks great. Thanks dealancer.
Drupal - The modern Lego game