2010-08-11 134 views
0

我有一個測試腳本,通過http post發送xml文件,當我在內部使用它時,它似乎可以正常工作。當我將腳本移動到可從外部訪問的Web服務器時,似乎沒有任何事情發生。任何任何想法?通過http接收xml文件post

<?php 
    if ($_SERVER['REQUEST_METHOD'] == 'POST') 
{ 
    $inp = fopen("php://input"); 
    $outp = fopen("xmlfile" . date("YmdHis") . ".xml", "w"); 
    while (!feof($inp)) { 
     $buffer = fread($inp, 8192); 
     fwrite($outp, $buffer); 
    }   
    fclose($inp); 
    fclose($outp); 
    echo "<html><head>test response</head><body>OK</body></html>"; 
} 
?> 

要發佈的XML我使用捲曲,不知道這是否是問題?我不發送到安全連接(HTTPS):

function httpsPost($Url, $xml_data) 
{  
    //Initialisation 
    $ch=curl_init(); 

    //Set parameters 
    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); 
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); 

    curl_setopt($ch, CURLOPT_URL, $Url); 

    //Return a variable instead of posting it directly 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    //Activate the POST method 
    curl_setopt($ch, CURLOPT_POST, 1); 

    //Request 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 4); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 

    //execute the connexion 
    $result = curl_exec($ch); 

    //Close it 
    curl_close($ch); 
    return $result; 
} 

回答

0

確保您的服務器上allow_url_fopen設置從php.ini中開啓。

話雖如此,請注意關於該設置的security concerns

更新:看到

嘗試,如果有任何錯誤,請打開錯誤報告,把這兩條線在你的腳本的頂部:

ini_set('display_errors', true); 
error_reporting(E_ALL); 
+0

嗨,是的,它確實需要設置allow_url_fopen =在 – thegunner 2010-08-11 10:54:58

+0

@thegunner:請參閱我的更新。 – Sarfraz 2010-08-11 10:58:07

+0

嗨,謝謝。我試過,似乎給任何錯誤。基本上,網絡服務器上的腳本只是上面的代碼+你的更新。不知道什麼是概率! – thegunner 2010-08-11 11:43:37

0

一些其他的事情來檢查:

  1. php://input不可用,如果窗體上有enctype=multipart/form-data
  2. php://input只能讀一次(不太可能,除非是你還沒有表現出對你的腳本其他部分)
  3. POST數據大小不超過Apache的LimitRequestBody和/或PHP的upload_max_size/post_max_size

任何原因你必須閱讀原始輸入,並不能基本上做fwrite($outp, $_POST['xml'])