dongyejun1983 2015-10-04 15:12
浏览 40

PHP Web Service与SSL身份验证的连接

I was given a project to connect to a webservice, executes certain action. Ther ewebservice required authentication. I was provided with the WSDL url and the certificate copy. I was not able to successfully connect to it using soapClient, I get this message:

PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://somesite.com/WebService.svc?WSDL' : failed to load external entity "https://somesite.com/WebService.svc?WSDL"

Any advice, why i got this message?

Here's my code:

$url = 'https://somesite.com/WebService.svc?WSDL';
$certFile = 'certificate/cert.crt';
$keyFile='certificate/cert.key';
$caFile='certificate/cert.csr'; 
        
$client = new SoapClient($url, 
                array(
                    'local_cert'    => $certFile, 
                    'style'         => SOAP_RPC,
                    'use'           => SOAP_ENCODED,
                    'soap_version'  => SOAP_1_2,
                    'authentication'=> SOAP_AUTHENTICATION_DIGEST,
                    'ssl'           => array(                        
                        'verifypeer' => false,
                        'verifyhost' => false,
                        'key' => $keyFile,
                        'cafile' => $caFile,
                        'allow_self_signed' => true
                    ),
                    'https' => array(
                        'curl_verify_ssl_peer'  => false,
                        'curl_verify_ssl_host'  => false
                    ),
                    'cache_wsdl'    => WSDL_CACHE_NONE,
                    'cache_ttl'     => 86400,
                    'trace'         => true,
                    'exceptions'    => true,
                )
    );

Do you have any idea what's missing that made this fail? I've tried connecting it thru curl, I can succesfully connect. My problem with CURL is that I don't know how to call the actions in the webservice like "logme","postMessages" and etc.

Here's my CURL code:

$username = 'webservice';
$password ='abcdef';
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
                            <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                              <soap:Body>
                                <logme>
                                  <user>'.$username.'</user>
                                 <pass>'.$password.'</pass> 
                                </logme>
                              </soap:Body>
                            </soap:Envelope>';  
    $conn = curl_init();
    curl_setopt( $conn, CURLOPT_SSLCERT, $certFile);        
    curl_setopt( $conn, CURLOPT_URL, $url );
    curl_setopt( $conn, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
    curl_setopt( $conn, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $conn, CURLOPT_FOLLOWLOCATION,true );
    curl_setopt( $conn, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt( $conn, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt( $conn, CURLOPT_SSLKEY, $keyFile);
    curl_setopt( $conn, CURLOPT_CAINFO, $caFile);
    curl_setopt( $conn, CURLOPT_SSLCERT, $certFile);
    curl_setopt($conn, CURLOPT_POST, true );
    curl_setopt($conn, CURLOPT_POSTFIELDS, $xml_post_string); 
            
    $client = curl_exec($conn);
    if($client === false)
    {
        echo 'Curl error: ' . curl_error($conn);
    }
    else
    {
        echo 'Congrats, no error!'; 
    }

    curl_close($conn);

When executing the CURL code, I will got the message "Congrats, no error!". SO my problem is, after the successfull connection. I don't know how to call the action of the WSDL or send request to the service. Any advice?

I have an update regarding the curl, this is the error message that I got

"HTTP/1.1 415 Cannot process the message because the content type 'text/xml;charset="utf-8"' was not the expected type 'application/soap+xml; charset=utf-8'.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用stata画出文献中常见的安慰剂检验图
    • ¥15 c语言链表结构体数据插入
    • ¥40 使用MATLAB解答线性代数问题
    • ¥15 COCOS的问题COCOS的问题
    • ¥15 FPGA-SRIO初始化失败
    • ¥15 MapReduce实现倒排索引失败
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型