Php 函数通过cURL发送XML

Php 函数通过cURL发送XML,php,curl,Php,Curl,下面是我的函数,它应该将XML发送到配置中指定的服务器,然后将响应(即XML)转换为数组 public function xmlResponse($data) { // sends the request to Atheme's XMLRPC interface via cURL $request = curl_init(); curl_setopt($request, CURLOPT_URL, $this->atheme_host); curl_setop

下面是我的函数,它应该将XML发送到配置中指定的服务器,然后将响应(即XML)转换为数组

public function xmlResponse($data) {
    // sends the request to Atheme's XMLRPC interface via cURL
    $request = curl_init();
    curl_setopt($request, CURLOPT_URL, $this->atheme_host);
    curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($request, CURLOPT_TIMEOUT, 6);
    curl_setopt($request, CURLOPT_POSTFIELDS, $data);
    curl_setopt($request, CURLINFO_HEADER_OUT, true);
    curl_setopt($request, CURLOPT_HTTPHEADER, array('Connection: close', 'Content-Type: text/xml'));
    $response = curl_exec($request);
    curl_close($request);

    // converts recieved XML into a PHP array and returns
    return json_decode(json_encode((array) simplexml_load_string($response)), 1);
}
但是,当我进行var_转储时,返回False。我不确定是什么问题,已经诊断了一段时间了。如果有人能指出问题和解决办法,我将不胜感激。我想是卷发有问题


谢谢

不熟悉Atheme或其API,我不确定这是否有帮助,但一些接受XML的API的工作方式如下:

$header = "Connection: close\r\n";
$header .= "Content-Type: text/xml\r\n\r\n";
$header .= $data;

$request = curl_init();
curl_setopt($request, CURLOPT_URL, $this->atheme_host);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_TIMEOUT, 6);
curl_setopt($request, CURLOPT_HEADER, false);
curl_setopt($request, CURLOPT_CUSTOMREQUEST, $header);
$response = curl_exec($request);
curl_close($request);

显示
$data
var_dump
,它可能不是正确的post字符串。`atheme.loginSample Usernamepassword123123.456.78.94`这是正在发送的XML。是的,当您将该数据作为CURLOPT_POSTFIELDS的值传递时,您需要将其保存。因此
curl_setopt($request,CURLOPT_POSTFIELDS,urlencode($data))
会起作用吗?这样做你会更幸运是的,如果你把一个字符串传递给CURLOPT_POSTFIELDS,它必须是URLCoded。