我正在尝试做的是设置一个XAMPP apache,在其上创建一个脚本,一旦它被调用,就写进一个文件中:
- HTTP 标头属性
- 内容(正文 - 如 Web 服务 XML 等)
这似乎是一件小事,但是看起来我无法通过谷歌找到解决方案......帮助将不胜感激,提前感谢!
<?php
$request = "";
//printing headers
foreach (getallheaders() as $name => $value) {
$request.= "$name: $value'n";
}
//printing body.. this part does not work any of it...
foreach ($_POST as $name => $value) {
$request.= "$name: $value'n";
}
//$request.="++++++++++++++++++++++'n"
foreach ($_FILES as $name => $value) {
$request.= "$name: $value'n";
//$request.="++++++++++++++++++++++'n"
foreach ($value as $name2 => $value2) {
$request.= "$name2: $value2'n";
//$request.="++++++++++++++++++++++'n"
}
}
$request.=$_FILES['document.xml']['D:'Software'xampp'tmp'phpA521.tmp'];
$request.=@file_get_contents('php://input');
file_put_contents('result/'.date('Y-m-d H_i_s').'.log',$request);
?>
$_POST
变量仅针对特定请求类型填充。文档将$_POST
描述为:
当使用application/x-www-form-urlencode或multipart/form-data作为请求中的HTTP Content-Type时,通过HTTP POST方法传递给当前脚本的变量的关联数组。
在您的情况下,内容类型是不同的,应该/将被指定为:
Content-Type: application/soap+xml;
对$_FILES
变量也有类似的限制。文档指出:
注:
请确保您的文件上传表单具有属性 enctype="multipart/form-data",否则文件上传将不起作用。全局
$_FILES
将包含所有上传的文件信息。
要访问已发布的数据,请按照有关 I/O 流的文档中所述进行操作:
php://input
是一个只读流,允许您从请求正文读取原始数据。对于 POST 请求,最好使用php://input
因此,您将按如下方式执行此操作:
$postedData = file_get_contents('php://input');
然后,您可以将其解析为 XML:
$xmlData = simplexml_load_string(trim($postedData));