2010-08-11 72 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'])