duangou1953 2016-08-03 07:26
浏览 79

在Php中使用CURL的Soap客户端请求不起作用

How can I create php soap request to look like this. I am unable to get the response in Php curl. But fiddler web debugger is working really well with the code.

Here is the raw request:

POST http://195.230.180.189:8280/services/TopupService?wsdl HTTP/0.9 Host: 195.230.180.189:8280 Content-Length: 691

<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:top="http://www.inew-cs.com/mvno/integration/TopupService/">
    <soapenv:Header/>
    <soapenv:Body>
     <top:TopupRequest>
      <amount>1</amount>
      <amountUnitRelation>1</amountUnitRelation>
      <subscriber>
       <msisdn>8801701340002</msisdn>
      </subscriber>
      <source>
       <distributorId>PayWell</distributorId>
      </source>
      <referenceId>12345</referenceId>
      <transactionId>09876543</transactionId>
     </top:TopupRequest>
    </soapenv:Body>
   </soapenv:Envelope>

In Php curl request:

$url="http://195.230.180.189:8280/services/TopupService?wsdl"; 
   $xml='<?xml version="1.0"?>
     <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:top="http://www.inew-cs.com/mvno/integration/TopupService/">
       <soapenv:Header/>
       <soapenv:Body>
        <top:TopupRequest>
         <amount>1</amount>
         <amountUnitRelation>1</amountUnitRelation>
         <subscriber>
          <msisdn>8801701340002</msisdn>
         </subscriber>
         <source>
          <distributorId>100</distributorId>
         </source>
         <referenceId>12345</referenceId>
         <transactionId>09876543</transactionId>
        </top:TopupRequest>
       </soapenv:Body>
         </soapenv:Envelope>'; 
   $headers = array(
       "Content-type: text/xml",
       "Content-length: " . strlen($xml),
       "Connection: close"
      );
     $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL,$url);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 30);
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);

     echo $result = curl_exec($ch);
     if(curl_exec($ch) === false)
     {
      echo 'Curl error: ' . curl_error($ch);
     }
     else
     {
      //echo 'Operation completed without any errors';
     }
     // Close handle
     curl_close($ch);
  • 写回答

1条回答 默认 最新

  • dsjswclzh40259075 2016-08-03 12:58
    关注

    You should not post to that URL. That is not a service endpoint, it is the WSDL, which defines the provided operations.

    PHP SoapClient class allows you to build soap requests easily:

    $wsdl = 'http://195.230.180.189:8280/services/TopupService?wsdl';
    
    $options = [
        'trace' => true,
        'cache' => WSDL_CACHE_NONE,
        'exceptions' => true
    ];
    
    $client = new SoapClient($wsdl, $options);
    
    $payload = [
        'amount' => 1,
        'amountUnitRelation' => 1,
        'subscriber' => [
            'msisdn' => '8801701340002'
        ],
        'source' => [
            'distributorId' => 'PayWell'
        ],
        'referenceId' => '12345',
        'transactionId' => '09876543',
    ];
    
    $response = $client->topup($payload);
    

    After parsing the given wsdl, the $client now has the method topup, as defined by <wsdl:operation>.

    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像