0

我有一个测试脚本可以通过 http post 接收一个 xml 文件,当我在内部使用它时它似乎工作正常。当我将脚本移动到可以从外部访问的 Web 服务器时,似乎没有发生任何事情。有人有什么想法吗?

<?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>";
}
?>

要发布我正在使用 curl 的 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;
 }
4

2 回答 2

0

其他一些需要检查的事情:

  1. php://input如果表单有,则不可用enctype=multipart/form-data
  2. php://input只能阅读一次(不太可能,除非您的脚本还有其他部分未显示)
  3. POST 数据大小不超过 ApacheLimitRequestBody和/或 PHP 的upload_max_size/post_max_size

你有什么理由必须阅读原始输入并且基本上不能这样做fwrite($outp, $_POST['xml'])

于 2010-08-11T13:04:06.390 回答
0

确保allow_url_fopen从 php.ini 打开您的服务器设置。

话虽如此,请注意有关该设置的安全问题。

更新:

试试看有没有报错,打开报错,把这两行放在你的脚本上面:

ini_set('display_errors', true);
error_reporting(E_ALL);
于 2010-08-11T10:52:59.330 回答