duanhe0817825 2013-10-16 17:12 采纳率: 100%
浏览 27
已采纳

PHP SOAP,如何请求这个

here is the think, I can request successfully the first, this gives me one ID, I must use this ID for the second request, but the second how?

 try {
    $clienteSOAP = new SoapClient ( 'someservicehere' );
    $header = array('Username' => 'user', 'Password' => 'pass', 'DeviceType'=> 3,'Platform'=>'1');
    $response = $clienteSOAP->GetSession($header);
    //echo $response->SessionID:
    //15987451
    $header2 = array('Username' => 'user', 'Password' => 'pass','SessionID' => '15987451' , 'DeviceType'=> 3,'Platform'=>'1');
    $clienteSOAP->GetBalance($header2);
    //GetBalance throws error,
 } catch ( SoapFault $e ) {
    var_dump ( $e );
 }

the xml for GetSession, this works great!!!

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ext="someTextHere">
    <soapenv:Header/>
    <soapenv:Body>
       <ext:GetSessionRequest>
          <ext:Username></ext:Username>
          <ext:Password></ext:Password>
          <ext:DeviceType></ext:DeviceType>
          <!--Optional:-->
          <ext:Platform></ext:Platform>
       </ext:GetSessionRequest>
    </soapenv:Body>
 </soapenv:Envelope>

but for this, how?

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ext="SomeTextHereToo">
    <soapenv:Header/>
    <soapenv:Body>
       <ext:GetBalanceRequest>
          <ext:AuthenticationData>
             <!--Optional:-->
             <ext:Username></ext:Username>
             <!--Optional:-->
             <ext:Password></ext:Password>
             <!--Optional:-->
             <ext:SessionID></ext:SessionID>
          </ext:AuthenticationData>
          <ext:DeviceType></ext:DeviceType>
          <!--Optional:-->
          <ext:Platform></ext:Platform>
       </ext:GetBalanceRequest>
    </soapenv:Body>
 </soapenv:Envelope>
  • 写回答

1条回答 默认 最新

  • douyou8266 2013-10-19 11:15
    关注

    You have to wrap your authentication data in a separate array, in the second definition there is an additional element wrapping the authentication credentials ().

    This should work:

    try {
       $clienteSOAP = new SoapClient ('someservicehere');
       $header = array('Username' => 'user', 'Password' => 'pass', 'DeviceType'=> 3,'Platform'=>'1');
       $response = $clienteSOAP->GetSession($header);
       $header2 = array('AuthenticationData' => array(
                            'Username' => 'user',
                            'Password' => 'pass',
                            'SessionID' => '15987451'
                        ),
                        'DeviceType'=> 3,
                        'Platform'=>'1'
                   );
       $clienteSOAP->GetBalance($header2);
    } catch (SoapFault $e) {
       var_dump ($e);
    }
    

    Since username, password and sessionid are all optional I guess you can authenticate either with username and password OR sessionid. So you probably don't have to supply username and password in the second call.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀