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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!