卷曲POST字段未发布

时间:2010-10-26 16:31:29

标签: php curl

我已经验证$requestDom->saveXml()正在返回有效的XML但是在目标网址上我有print_r($ _ POST)并且它没有收到任何内容。我在这里错过了什么吗? : - \

    $connection = curl_init();
    curl_setopt($connection, CURLOPT_POSTFIELDS, array(
        'xml' => $requestDom->saveXml()
    ));
    curl_setopt($connection, CURLOPT_HEADER, false); //with or without this option, it doesn't work
    curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($connection, CURLOPT_POST, true);
    curl_setopt($connection, CURLOPT_URL, 'http://sample.com');

    $response = curl_exec($connection);

2 个答案:

答案 0 :(得分:1)

经过进一步研究,我发现将xml发布到目标网址的正确方法是....

$connection = curl_init();
curl_setopt($connection, CURLOPT_POSTFIELDS, $requestDom->saveXml());
curl_setopt($connection, CURLOPT_HEADER, false); //with or without this option, it doesn't work
curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($connection, CURLOPT_POST, true);
curl_setopt($connection, CURLOPT_URL, 'http://sample.com');

$response = curl_exec($connection);

然后在接收此信息的文件上,使用:

            $post = file_get_contents("php://input");
            $request = simplexml_load_string($post);

答案 1 :(得分:0)

我可以重现这个问题。在EFnet上的#php.pecl频道中寻求帮助。