【问题标题】:PHP write soap request to filePHP将soap请求写入文件
【发布时间】:2016-01-25 12:46:18
【问题描述】:

我正在尝试做的是设置一个 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);
?>

【问题讨论】:

  • 我们应该为您提供什么帮助?为你写代码?
  • 对不起,我忘了发帖
  • 还有什么问题?有什么错误吗?
  • 没有错误,只是没有内容......既不是帖子,也不是文档,也不是附件
  • 您是否发出过发布请求?如果是这样,您能否显示您提交的表单的 HTML 代码?

标签: php apache http http-headers


【解决方案1】:

$_POST 变量只会为特定的请求类型填充。 The docs$_POST 描述为:

当使用 application/x-www-form-urlencodedmultipart/form-data 时,通过 HTTP POST 方法传递给当前脚本的变量关联数组请求中的 HTTP Content-Type。

在您的情况下,Content-Type 是不同的,应该/将被指定为:

Content-Type: application/soap+xml;

$_FILES 变量也有类似的限制。 The docs状态:

注意:
确保您的文件上传表单具有属性 enctype="multipart/form-data" 否则文件上传将无法正常工作。

全局$_FILES将包含所有上传的文件信息。

要访问发布的数据,请按照documentation on I/O streams 中的说明进行操作:

php://input 是一个只读流,允许您从请求正文中读取原始数据。对于POST请求,最好使用php://input

所以你可以这样做:

$postedData = file_get_contents('php://input');

然后您可以将其解析为 XML:

$xmlData = simplexml_load_string(trim($postedData)); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多