1. <i id='EAuDo'><tr id='EAuDo'><dt id='EAuDo'><q id='EAuDo'><span id='EAuDo'><b id='EAuDo'><form id='EAuDo'><ins id='EAuDo'></ins><ul id='EAuDo'></ul><sub id='EAuDo'></sub></form><legend id='EAuDo'></legend><bdo id='EAuDo'><pre id='EAuDo'><center id='EAuDo'></center></pre></bdo></b><th id='EAuDo'></th></span></q></dt></tr></i><div id='EAuDo'><tfoot id='EAuDo'></tfoot><dl id='EAuDo'><fieldset id='EAuDo'></fieldset></dl></div>
  2. <small id='EAuDo'></small><noframes id='EAuDo'>

    • <bdo id='EAuDo'></bdo><ul id='EAuDo'></ul>

      <legend id='EAuDo'><style id='EAuDo'><dir id='EAuDo'><q id='EAuDo'></q></dir></style></legend>

      <tfoot id='EAuDo'></tfoot>
    1. Php SoapClient stream_context 选项

      时间:2023-05-22

      <legend id='qcHD2'><style id='qcHD2'><dir id='qcHD2'><q id='qcHD2'></q></dir></style></legend>

          <tfoot id='qcHD2'></tfoot>

            • <bdo id='qcHD2'></bdo><ul id='qcHD2'></ul>
              • <i id='qcHD2'><tr id='qcHD2'><dt id='qcHD2'><q id='qcHD2'><span id='qcHD2'><b id='qcHD2'><form id='qcHD2'><ins id='qcHD2'></ins><ul id='qcHD2'></ul><sub id='qcHD2'></sub></form><legend id='qcHD2'></legend><bdo id='qcHD2'><pre id='qcHD2'><center id='qcHD2'></center></pre></bdo></b><th id='qcHD2'></th></span></q></dt></tr></i><div id='qcHD2'><tfoot id='qcHD2'></tfoot><dl id='qcHD2'><fieldset id='qcHD2'></fieldset></dl></div>
                  <tbody id='qcHD2'></tbody>

                <small id='qcHD2'></small><noframes id='qcHD2'>

                本文介绍了Php SoapClient stream_context 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我想使用第三方的网络服务.要使用 Web 服务,我需要使用 HTTPS 连接.我的问题是,对于开发过程,我有一个带有无效证书的测试 api.我想设置 SoapClient no 来验证服务器的证书.这是我尝试的方法:

                I want to use a third party's web service. To use the web service I need to connect with HTTPS. My problem is that for the development process I have a test api with an invalid certificate. I would like to set SoapClient no to verify the server's certificate. Here is the way I tried:

                $opts = array(
                    'ssl'   => array(
                            'verify_peer'          => false
                        ),
                    'https' => array(
                            'curl_verify_ssl_peer'  => false,
                            'curl_verify_ssl_host'  => false
                     )
                );
                $streamContext = stream_context_create($opts);
                $client = new SoapClient("https://urlToSoapWs",
                  array(
                      'login'             => 'user',
                      'password'          => 'pwd',
                      'authentication'    => SOAP_AUTHENTICATION_BASIC,
                      'local_cert'        => file_get_contents('C:/somelocation/1.pem'),
                      'passphrase'        => 'passphrase',
                      'stream_context'    => $streamContext
                  ));
                

                我也尝试过 CURL 并且成功了!但我想使用 SoapClient.您可以在下面找到带有 CURL 的代码:

                I also tried with CURL and worked! But I want to use SoapClient. You can find the code with CURL below:

                // create a new cURL resource
                $ch = curl_init("https://urlToSoapWs");
                
                // setting the request type to POST: 
                curl_setopt($ch, CURLOPT_POST, 1);
                
                curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); 
                // setting the authorization method to BASIC: 
                curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
                // supplying your credentials: 
                curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");
                
                $body = "<SOAP-ENV:Envelope>somexmlhere</SOAP-ENV:Envelope>";
                // filling the request body with your SOAP message: 
                curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
                
                // configuring cURL not to verify the server certificate: 
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                curl_setopt($ch, CURLOPT_SSLCERT, "pathToTheCertificatePemFile");
                curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "pwd");
                //curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM");
                
                curl_setopt($ch, CURLOPT_SSLKEY, "pathTotheKeyFile");
                curl_setopt($ch, CURLOPT_SSLKEYPASSWD, "pwd");
                
                // telling cURL to return the HTTP response body as operation result 
                // value when calling curl_exec: 
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
                // calling cURL and saving the SOAP response message in a variable which 
                // contains a string like "<SOAP-ENV:Envelope ...>...</SOAP-ENV:Envelope>": 
                
                
                $result = curl_exec($ch);
                // closing cURL: 
                curl_close($ch);
                

                如果您在我使用 SoapClient 提供的代码中发现了错误,请发布它.谢谢.

                If you have found the bug in the code that I provided using the SoapClient please post it. Thanks.

                推荐答案

                也许不是无效的证书是个问题,更多的是 SSLv2/3 Handshake;您可以尝试像这样手动指定密码吗:

                Maybe not the invalid Certificate is a Problem, more the SSLv2/3 Handshake; can you try manually specifing a Cipher like this:

                $stream_opts = array(
                //      'ssl'=>array('ciphers'=>"3DES" // also working
                //      further ciphers on http://www.openssl.org/docs/apps/ciphers.html
                        'ssl'=>array('ciphers'=>"SHA1"
                      )
                );
                
                $myStreamContext = stream_context_create($stream_opts);
                $soapOptions['stream_context'] = $stream_opts;
                $soapClient = new SoapAuthClient("https://...", $soapOptions);
                

                祝你好运!

                这篇关于Php SoapClient stream_context 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何将此 XML 请求转换为 php 中的数组? 下一篇:如何在php中使用soap类(举例)?

                相关文章

                最新文章

              • <small id='tRPHj'></small><noframes id='tRPHj'>

                <legend id='tRPHj'><style id='tRPHj'><dir id='tRPHj'><q id='tRPHj'></q></dir></style></legend>
                <i id='tRPHj'><tr id='tRPHj'><dt id='tRPHj'><q id='tRPHj'><span id='tRPHj'><b id='tRPHj'><form id='tRPHj'><ins id='tRPHj'></ins><ul id='tRPHj'></ul><sub id='tRPHj'></sub></form><legend id='tRPHj'></legend><bdo id='tRPHj'><pre id='tRPHj'><center id='tRPHj'></center></pre></bdo></b><th id='tRPHj'></th></span></q></dt></tr></i><div id='tRPHj'><tfoot id='tRPHj'></tfoot><dl id='tRPHj'><fieldset id='tRPHj'></fieldset></dl></div>
                  <bdo id='tRPHj'></bdo><ul id='tRPHj'></ul>

                  1. <tfoot id='tRPHj'></tfoot>