无法连接到WSDL

时间:2014-08-05 15:07:14

标签: php web-services soap https

我正在使用旧版本的OpenSSL(OpenSSL 0.9.8o),我被迫使用较新的OpenSSL 1.0.1e-fips,因为我无法连接到WSDL:

Message: SoapClient::SoapClient(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

我需要禁用SSL认证检查,我试过了:

    $client = new SoapClient("https://IP:443/sdk/vimService?wsdl",
        array(
            "trace" => 1,
            "location" => "https://IP:443/sdk/",
            "stream_context" => stream_context_create(
                array(
                    'ssl' => array(
                        'verify_peer'       => false,
                        'allow_self_signed' => true,
                    )
                )
            )
        ) 
    );

`

它抛出:

Message: SoapClient::SoapClient(): Peer certificate CN= localhost.localdom'与预期的CN = SAME IP AS IN SoapClient()'

不匹配

然后我在'peer_name'=> 'localhost.localdom',中添加了stream_context,然后它说XML文件为空:

Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document

PHP 5.5

4 个答案:

答案 0 :(得分:25)

哎呀,我找到了问题。

您可以使用稳定的PHP 5.5版本来避免这种混乱

最近我了解到错误:“看起来我们没有XML文档”是由于​​PHP版本引起的 - 5.5中的PHP 5.6就像魅力一样。

如何在PHP 5.6中修复它

1)在PHP 5.6中删除SSL证书检查:

在5.6版本中默认启用SSL认证,因此如果要禁用它,则必须传递上下文流:

    "stream_context" => stream_context_create(
        array(
            'ssl' => array(
                'verify_peer'       => false,
                'verify_peer_name'  => false,
            )
        )
    )

2)删除了?wsdl并添加了.wsdl代替?wsdl,但它并没有让我失望)

<?php

$client = new SoapClient("https://IP:443/sdk/vimService.wsdl",
    array(
        "trace" => 1,
        "location" => "https://IP:443/sdk/",
        'exceptions' => 1,
        "stream_context" => stream_context_create(
            array(
                'ssl' => array(
                    'verify_peer'       => false,
                    'verify_peer_name'  => false,
                )
            )
        )
    ) 
);


$soapmsg["_this"] = array( "_" => "ServiceInstance", "type" => "ServiceInstance");

$result = $client->RetrieveServiceContent($soapmsg);
$ServiceContent = $result->returnval;

$soapmsg = NULL;
$soapmsg["_this"] = $ServiceContent->sessionManager;
$soapmsg["userName"] = "USERNAME";
$soapmsg["password"] = "PASSWORD";

$result = $client->Login($soapmsg);
$UserSession = $result->returnval;

echo "User, " . $UserSession->userName . ", successfully logged in!\n";

$soapmsg = NULL;
$soapmsg["_this"] = $ServiceContent->sessionManager;
$result = $client->Logout($soapmsg);

答案 1 :(得分:1)

在我的情况下,stream_context_create没有工作 所以我在这里下载这个文件:https://curl.haxx.se/ca/cacert.pem

并将其放在我的localhost中:F:\ xampp \ apache \ cert.pem 并给了同样的道路 我的phpini中的openssl.cafile = F:\ xampp \ apache \ cert.pem

这使得本地主机获得证书并且事情很有效...... !! 发布这个以防万一这可能有助于我的情况。

答案 2 :(得分:1)

就我而言,需要添加crypt_method

[uwsgi]
module = main
callable = app.app

答案 3 :(得分:0)

在我的案例中,“ stream_context”起到了神奇作用,我刚刚添加了代码:

`"stream_context" => stream_context_create(
   array(
      'ssl' => array(
           'verify_peer'       => false,
           'verify_peer_name'  => false,
      )
   )
)`