使用PHP的SoapClient处理认证过的https webservice是彻底没有问题的。可是若是遇到一些不去认证https而是用自建的证书来作https的时候就会有问题,通常会报“Could not connect to host.”错误。php
解决方式之一就是让SoapClient忽略https的ssl认证,直接跳过认证的环节,直接贴代码吧web
$context = stream_context_create( array ( 'ssl' => array ( 'verify_peer' => false, 'allow_self_signed' => true ), )); $options['stream_context'] = $context; $client = new SoapClient($url, $options);
verify_peer:指定是否验证ssl,默认为trueurl
allow_self_signed:是否容许自建证书的https服务,默认为falsespa
贴上官方的文档:http://php.net/manual/en/context.ssl.php .net
原创文章,转载请注明出处code