简体   繁体   English

使用 Curl 更正 XML 请求:得到空白 XML 响应

[英]Correct XML request with Curl: getting blank XML response

I was trying to hit XML request from PHP SOAP Client according to the following provided SOAP API documentation.我试图根据以下提供的 SOAP API 文档从 8832478985188 SOAP 客户端发送 XML 请求。


WSDL Schema Refer to the following URL. WSDL Schema 参考以下URL。

http://[SERVER_IP]/PowerSuite/PSXMLSearch.asmx?wsdl http://[SERVER_IP]/PowerSuite/PSXMLSearch.asmx?wsdl

4 Input/Output 4.1 Search Supplier Code and Name (PSXMLSearchSupplier) 4 输入/输出 4.1 搜索供应商代码和名称 (PSXMLSearchSupplier)

  • Input: PSXML_SEARCH_SUPP输入:PSXML_SEARCH_SUPP
  • Output: PSXML_SEARCH_SUPP_Response Output:PSXML_SEARCH_SUPP_Response

6 Field definition 6 字段定义

6.1 PSXML_SEARCH_SUPP - The main entry point and the authentication information. 6.1 PSXML_SEARCH_SUPP - 主要入口点和身份验证信息。

  • MSGID消息标识符
  • USERID用户身份
  • PASSWORD密码
  • OPTION选项
  • SUPPNO支持号

But when i run with SOAP client it gives me a following error但是,当我使用 SOAP 客户端运行时,出现以下错误

Object reference not set to an instance of an object

So after long research on inte.net, i decided to send XML request via CURL, i have created following Schema for XML request and send it via CURL request因此,经过对 inte.net 的长期研究,我决定通过 CURL 发送 XML 请求,我为XML 请求创建了以下架构并通过 CURL 请求发送

 $soapUrl = "https://[MY_SERVER_DOMAIN]/PowerSuite/PSXMLSearch.asmx"; // asmx URL of WSDL

 // xml post structure

 $xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
                     <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                       <soap:Body>
                         <PSXML_SEARCH_SUPP xmlns="https://[MY_SERVER_DOMAIN]/PowerSuite/PSXMLSearch.asmx"> 
                           <MSGID>TRAVEK_E1</MSGID> 
                           <USERID>GCOT</USERID> 
                           <PASSWORD>CKHOSKIS6</PASSWORD> 
                           <OPTION>LIKE</OPTION> 
                           <SUPPNO>RK0048</SUPPNO> 
                         </PSXML_SEARCH_SUPP>
                       </soap:Body>
                     </soap:Envelope>'; 

    $headers = array(
                 "Content-type: text/xml;charset=\"utf-8\"",
                 "Accept: text/xml",
                 "Cache-Control: no-cache",
                 "Pragma: no-cache",
                 "SOAPAction: \"https://[MY_SERVER_DOMAIN]/PowerSuite\"",                
                 "Content-length: ".strlen($xml_post_string),
             ); 

     $url = $soapUrl;

     // PHP cURL  for https connection with auth
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_USERPWD, "GCONNECT:Connect@786");
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

     // converting
     $response = curl_exec($ch); 
     curl_close($ch);

     // converting
     $response1 = str_replace("<soap:Body>","",$response);
     $response2 = str_replace("</soap:Body>","",$response1);

     // convertingc to XML
     $parser = simplexml_load_string($response2);
     // user $parser to get your data out of XML response and to display it.
echo "<pre>"; 
print_r($parser); 
echo "</pre>";
die();

But even after that i only get empty XML response as can see below但即使在那之后,我也只会得到空的 XML 响应,如下所示

SimpleXMLElement Object
(
)

Please guide am i sending a correct XML schema, or their needs to be some thing amend into it?请指导我是否发送了正确的 XML 架构,或者他们需要对其进行一些修改?

I checked with RapidAPI, it shows the correct response, i have shown the request in the image below:我检查了 RapidAPI,它显示了正确的响应,我在下图中显示了请求:

In FORM https://gcdnb.pbrd.co/images/a9NdABt6rXQl.png在表格https://gcdnb.pbrd.co/images/a9NdABt6rXQl.png

In XML XML

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xh="http://www.xmlhk.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <xh:PSXMLSearchSupplier>
         <!--Optional:-->
         <xh:PSXML_SEARCH_SUPP>
            <!--Optional:-->
            <xh:MSGID>TRAVEK_EBOOK001</xh:MSGID>
            <!--Optional:-->
            <xh:USERID>ABCUSER</xh:USERID>
            <!--Optional:-->
            <xh:PASSWORD>Connect@786</xh:PASSWORD>
            <!--Optional:-->
            <xh:OPTION>LIKE</xh:OPTION>
            <!--Optional:-->
            <xh:SUPPNO>ABDECS</xh:SUPPNO>
            <!--Optional:-->
            <xh:SUPPNAME>?</xh:SUPPNAME>
         </xh:PSXML_SEARCH_SUPP>
      </xh:PSXMLSearchSupplier>
   </soapenv:Body>
</soapenv:Envelope>

I tried the same above with CURL request and got that working, i found that,following to be changed in my previous CURL request, which on the raw tab in ReadyAPI我在上面对 CURL 请求进行了相同的尝试并使其正常工作,我发现在我之前的 CURL 请求中进行了更改,该请求位于ReadyAPI原始选项卡

"SOAPAction: \"http://www.xmlhk.com/PSXMLSearchSupplier\"",

To work this with SOAP Client i just need to used multi dimensional array with $params['PSXML_SEARCH_SUPP'] shows below要与 SOAP 客户端一起使用,我只需要使用多维数组$params['PSXML_SEARCH_SUPP']如下所示

$wsdl = "https://ps.gerrys.com.pk/PowerSuite/PSXMLSearch.asmx?WSDL";
        $params['PSXML_SEARCH_SUPP'] = array(
          'MSGID'   =>  "TRAVEK_EBOOK001",
          'USERID'  =>  "GCONNECT",
          'PASSWORD' => "Connect@786",
          'OPTION'  =>  'LIKE',
          'SUPPNO'  =>  'RK0048'
        ); 
      try {
          $soap = new SoapClient($wsdl);
          $data = $soap->PSXMLSearchSupplier($params);
            echo "<pre>"; 
            print_r($data); 
            echo "</pre>";
          die();                    
      }
      catch(Exception $e) {
          $e->getMessage();
          var_dump($e->getMessage());
          die();
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM