小编fid*_*zik的帖子

使用php从HTTP POST请求中检索XML

我已经检查了类似的问题,但没有一个能解决我面临的问题。

我正在构建一个Web服务,我想从HTTP POST请求中检索XML数据,操纵数据并返回响应。编写脚本时应考虑以下信息:

 The communication mode is HTTP POST (not SOAP) 
 The content type is text/xml. 
 The POST request will contain only XML
 The request will be a RAW POST directly to stream and NOT in a parameter.
Run Code Online (Sandbox Code Playgroud)

我已经尝试过,但是我的脚本没有从HTTP POST请求中捕获数据。

我的脚本:

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

  if(!empty($xml->MerchantReference)){
     $merchRef = (string)$xml->MerchantReference;
     $custRef = (int)$xml->CustReference;
     $username = (string)$xml->ServiceUsername;
     $password = (string)$xml->ServicePassword;
     $db->setQuery(Check if customer exists in database);
     if($db->countResultset() == 0)
     {
        header("Content-type: text/xml");
        echo "<?xml version='1.0' encoding='UTF-8'?>";
        echo "<CustomerInformationResponse>";
            echo "<MerchantReference>".$merchRef."</MerchantReference>";
            echo "<Customers>";
                echo …
Run Code Online (Sandbox Code Playgroud)

xml post http http-post

3
推荐指数
1
解决办法
9117
查看次数

标签 统计

http ×1

http-post ×1

post ×1

xml ×1