[英]PHP write soap request to file
what I'm trying to do it setting up an XAMPP apache, creating a script on it, which is once it is called, writing down into a file: 我正在尝试执行的操作是设置XAMPP Apache,在其上创建一个脚本,调用该脚本后,将其写下一个文件:
This seems to be a small thing, however it looks like I'm not able to find a solution via google... Help would be highly appreciated, thanks in advance! 这似乎是一件小事,但是看来我无法通过Google找到解决方案...非常感谢您的帮助,在此先感谢您!
<?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);
?>
The $_POST
variable only gets populated for specific request types. $_POST
变量仅填充特定的请求类型。 The docs describe $_POST
as: 文档将
$_POST
描述为:
An associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request.
当在请求中使用application / x-www-form-urlencoded或multipart / form-data作为HTTP Content-Type时,通过HTTP POST方法传递给当前脚本的变量的关联数组。
In your case the Content-Type is different and should/will be specified as: 在您的情况下,Content-Type是不同的,应该/将被指定为:
Content-Type: application/soap+xml;
There is a similar restriction on the $_FILES
variable. $_FILES
变量也有类似的限制。 The docs state: 文档状态:
Note:
注意:
Be sure your file upload form has attribute enctype="multipart/form-data" otherwise the file upload will not work.请确保您的文件上传表单具有属性enctype =“ multipart / form-data”,否则文件上传将无法进行。
The global
$_FILES
will contain all the uploaded file information.全局
$_FILES
将包含所有上载的文件信息。
To get access to the posted data, do as explained in the documentation on I/O streams : 要访问已发布的数据,请按照有关I / O流的文档中的说明进行操作 :
php://input
is a read-only stream that allows you to read raw data from the request body.php://input
是一个只读流,允许您从请求正文中读取原始数据。 In the case of POST requests, it is preferable to usephp://input
对于POST请求,最好使用
php://input
So you would do this as follows: 因此,您可以按照以下步骤进行操作:
$postedData = file_get_contents('php://input');
You could then parse this as XML: 然后,您可以将其解析为XML:
$xmlData = simplexml_load_string(trim($postedData));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.