douyan6742
2017-07-11 23:04
浏览 314
已采纳

PHP - 如何将https标头设置为soap ws请求

I'm using SoapUI 5.3.0 to test a SOAP ws request. I was requested to send user and password via https headers not via soap headers. It works well when I use this SoapUi tool:

SoapUI 5.3.0 Capture However, when I try to do it from php I always get an authentication error, exactly the same error I get when I use a wrong password on purpose, I've tried several combinations but none of them gave me expected results

code example:

$data['Contrato'] = '123456';
$data['FechaInicio'] = '11/07/2017';
$data['FechaFin'] ='11/07/2017';

$client = new SoapClient( "https://example.com/WebService?WSDL", array(
    "exceptions" => 0,
    "trace" => 1,
    'stream_context' => stream_context_create(array(
        'http' => array(
            'header' => 'Username:xxx@gmail.com\
\ Password:notrealpwd'
        ),
    )),
));

$result = $client->__soapCall('depositos', $data);

Does any of you knows what I am doing wrong?

图片转代码服务由CSDN问答提供 功能建议

我正在使用SoapUI 5.3.0测试SOAP ws请求。 我被要求发送用户和密码 通过https标题而不是通过soap标题。 当我使用这个SoapUi工具时效果很好:

然而,当我尝试 从php做的我总是得到一个身份验证错误,当我故意使用错误的密码时,我得到了完全相同的错误,我尝试了几种组合,但没有一个给我预期的结果

代码示例:

  $ data ['Contrato'] ='123456'; 
 $ data ['FechaInicio'] = '11 / 07/2017'; 
  $ data ['FechaFin'] = '11 / 07/2017'; 
 
 $ client = new SoapClient(“https://example.com/WebService?WSDL”,array(
“exceptions”=>  0,
“trace”=> 1,
'stream_context'=> stream_context_create(array(
'http'=> array(
'header'=>'用户名:  xxx@gmail.com \
 \
密码:notrealpwd'
),
)),
)); 
 
 $ result = $ client-> __ soapCall('depositos',$ data)  ; 
   
 
 

你们有谁知道我做错了吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题