Как разместить xml-данные в http-запросе drupal? У меня есть код этого завитка


Это следующий код завитка

    $ch = curl_init(); //initiate the curl session
    curl_setopt($ch, CURLOPT_URL, $url); //set to url to post to
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // tell curl to return data in a variable
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlrequest); // post the xml
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); // set timeout in seconds
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    $result['xml'] = curl_exec($ch);

Как мне изменить следующий код для использования drupal_http_request()?

Author: kiamlaluno, 2011-08-03

1 answers

Видя, как drupal_http_request() используется в _xmlrpc(), что-то вроде этого должно это сделать.

// The path to send the request
$url = "http://example.com/API_PATH_HERE";
// Example of valid xml code;
$xmlrequest = "<showId>0</showId><tag>123</tag>";

$response = drupal_http_request($url, array(
  'headers' => array('Content-Type' => 'text/xml'),
  'data' => $xmlrequest,
  'method' => 'POST',
  'timeout' => 10
));
// If there is no error return data
if (empty($response->error)) {
  $result['xml'] = $response->data;
}
 7
Author: Pierre Buyle, 2016-02-29 06:22:23