Problems posting a node to services using PHP REST

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by P.Smith on July 27, 2011 at 11:49pm

I am able to establish a login to services and a session name and session id is returned. However, when I try to post a new node a 401 error code is returned. I assumed that I just needed to send the cookie in the header?

The curl code I am using is:

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Accept: application/xml", "Cookie: " . $session_cookie));
$response = curl_exec($curl);

Where $session_cookie is in the format "session_name=session_id", e.g.:

SESS49960de5880e8c687434170f6476605b=ZEiSLtuRDjP2c3f0cJSaZgZQu6J1BIuMqJAi6-LCZpA

(I have no problems posting logging in and posting a node when using a Firefox rest client extension. The extension uses Firefox for the session cookie.)

I assume that the 401 returned is due to an error in the header? I have also tried:

$curl_setopt($curl, CURLOPT_COOKIE, $session_cookie);

Any would be greatly appreciated.

Comments

Please take a look at tests

Posted by ygerasimov on July 28, 2011 at 7:43am

Please take a look at tests that are shipped with services 3.x (file tests/functional/services.test). They use calls via curl so you should find all options you need.

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /