Question

I've run into a strange issue.

I have a few simple lines CURL code for calling an api service. This code runs perfectly fine when running outisde of Drupal (in php file in browser and cli), but when the file is included within Drupal (after the bootstrap), it operates deferentially.

Under normal condition, the result returned by the API service has many results, but when run within Drupal, it only returns one result.

I suspect Drupal is changing a setting that CURL is using, which is changing how the API is understanding the call.

Does anyone know what the problem might be caused by?

The code below is derived from our api class files written within a common library. We plan to use these in the future in other PHP projects.

Here is the code:

$params = array(
  'domain' => array(
    'www.domain1.com',
    'www.domain2.info',
    'www.domain3.in.th',
    'www.domain4.com',
    'www.domain5.in',
  )
);

$ch = curl_init();
curl_setopt_array($ch, array(
  CURLOPT_URL => 'http://api.postrank.com/v2/domain/activity?appkey=123456&format=json',
  CURLOPT_HEADER => false,
  CURLOPT_CONNECTTIMEOUT => 30,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_SSL_VERIFYPEER => false,
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => http_build_query($params)
));
$response = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);

print_r($response);
Was it helpful?

Solution

The answer was that Drupal changes the & in a querystring to & and the remote API service only processed the argument separator & and not &amp. So naturally, when it splits the post data up, it got only the first parameter in the array correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top