3

I want to use services module 3.x, drupal 7 and xmlrpc to create a node from a php client. However, I don't know how to deal with the authentication. I enable the session authentication but I don't know what I should do and I get error: HTTP/1.0 401 Unauthorized: Access denied for user anonymous.

ps: I can get session name and session id from user.login

1
  • change permissions for anonymous user and check again
    – iMeMyself
    Commented Sep 25, 2012 at 5:53

3 Answers 3

1
+50

Note: this is valid after SERVICES 3.5 (lower version are deprecated, anyway)

// USER LOGIN
$authenticate = xmlrpc($settings['server'], Array('user.login' => array($settings['user'] , $settings['password']),));

// CREATE HEADERS
$options['headers']['Cookie'] = $authenticate['session_name'] . '=' . $authenticate['sessid'];

// GET TOKEN
$token = xmlrpc(url($this->endpoint, array('absolute' => TRUE)), array('user.token' => array()), $this->headers);

//INSERT TOKEN INTO HEADERS
$options['headers']['X-CSRF-Token'] = $token['token'];

At this point you should be authenticated and could create nodes at will.

0

Please go through the below given link and I am sure it will help

How do I POST a new node using the Services module?

Before doing please read https://drupal.org/node/1354202 Services 3 - POST node.create with custom fields ...test your services first on various tools. link browser add-ons and other apps. after that you can use this services in any flatforms like PHP, JAVA ....etc

0

As you said After logging in using web service ,you are getting a response with session name and session id.For making a request to create a node ,you should specify the session name and session id in the header of the request. The session name and id are used for authentication,If it does not match with the current session,then you will not be authorized

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.