Monday, January 16, 2012

Drupal frustrations continue

Remember those old cartoons where the characters would open a door, only to discover another door behind it, then another, and another?  I have used that visual to illustrate the frustrations of software development to non-technical people. There is just no end of bugs to find and fix.Once one is repaired, another pops up.

I have been tracking my current problem down for more than three days now. All I want to do is retrieve a node from Drupal as XML so I can manipulate it in my own PHP coding. It should be simple, and it would be if the Drupal site I was trying to retrieve from was public.

There seems to be a bug or undiscovered setting that is preventing me from retrieving node content from my Drupal installation, which disallows anonymous users entirely.

As I posted earlier, I found an excellent sample of code posted by MichaelCole, and have been using it as my primary reference. Unfortunately, it seems that when trying to do an HTTP GET, passing the session auth data back to Drupal fails. I have tried countless combinations of methods to send the authentication strings, but none work.

These include PHP CURL options such as:
curl_setopt($curl, CURLOPT_COOKIESESSION, false); 
curl_setopt($curl, CURLOPT_COOKIEJAR, "cookiefile.txt");
curl_setopt($curl, CURLOPT_HTTPGET, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); (along with JSON-encoding the session cookie)

Multiple methods of sending the data, including:
$request_data = array(
    $sessData[0] => $sessData[1],
    "method" => "node.get",
    "nid" => 18
    );
$request_data = http_build_query($request_data, '', '&'); // Format post data as application/x-www-form-urlencoded
$service_url.="?$request_data"; //append the data as a GET qstring

According to the REST entry on Wikipedia , GET must be used to retrieve a resource, so utilizing POST as is done in the login procedure seems to not be an option.

I will keep digging at this and post up if when I find a solution (think positive).

No comments:

Post a Comment