PHP SoapClient,如何连接证书?

时间:2017-10-23 17:53:03

标签: php ssl soap

我创建了新的SoapClient

$this->soap = new \SoapClient($this->wdls // WDLS with coorect host
, [
    'exceptions' => 0,
    'trace' => TRUE,
    'local_cert' => $this->local_cert, // PEM file
    'passphrase' => $this->passphrase, // password for PEM
    'authentication' => SOAP_AUTHENTICATION_DIGEST,
    'ssl_method' => SOAP_SSL_METHOD_SSLv2,
    'cache_wsdl' => WSDL_CACHE_NONE,
    ]);
$this->soap->getInfo([...]);

但是我收到错误:无法连接到主机

我使用Firefox测试了连接,我能够连接。可能是什么问题?

1 个答案:

答案 0 :(得分:0)

开始 - 在服务器上关闭了端口。所以我无法访问远程服务器。 毕竟TLS 1.2存在问题,内置的SOAP客户端不接受配置,它帮助我手动指定协议版本。

$this->soap = new \SoapClient($this->wdls, [
    'exceptions' => 1,
    'trace' => TRUE,
    'local_cert' => $this->local_cert,
    'passphrase' => $this->passphrase,
    //'ssl_method' => SOAP_SSL_METHOD_SSLv2, // not work!
    'authentication' => SOAP_AUTHENTICATION_DIGEST,
    "soap_version"  => SOAP_1_2,
    'cache_wsdl' => WSDL_CACHE_NONE,
    'stream_context' => stream_context_create([
        'ssl' => [
            'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, // it's work!
        ]
    ]),
]);