我有一个测试脚本以收到xml文件的通过http后,它看来工作确定,当我使用它。当我移动脚本网络服务器,这可以从外部访问没有出现将发生的事情。任何人的任何想法?

<?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;
 }
有帮助吗?

解决方案

请确保您的服务器上 allow_url_fopen 设置从php.ini中导通。

说了这么多,要注意的安全问题的有关设置。

<强>更新

尝试,看看是否有任何错误,请打开错误报告,把这两条线在你的脚本的顶部:

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

其他提示

一些其他的事情要检查:

  1. php://input 不能用如果有形式 enctype=multipart/form-data
  2. php://input 只能一次读取(不有可能的,除非还有其他的部分给你的剧本你还没有显示)
  3. 后数据的尺寸不超过Apache LimitRequestBody 和/或PHP的 upload_max_size/post_max_size

任何原因你们已经阅读了原输入和不能做的基本上 fwrite($outp, $_POST['xml'])?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top