2010-10-26 95 views
0

我已驗證$requestDom->saveXml()正在返回有效的XML,但在目標URL處有print_r($ _ POST),並且它不會收到任何內容。我在這裏錯過了什麼嗎? : - \Curl 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); 

回答

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); 
0

我可以重現該問題。在EFnet的#php.pecl頻道尋求幫助。