PHP7 cURL和SOAP请求SSL失败

时间:2022-10-19 18:18:52

I'm using PHP 7.0.25 in a vagrant VM with ubuntu 16.04

我在使用ubuntu 16.04的流浪虚拟机中使用PHP 7.0.25

I need to make a request to this SOAP API: https://ws.ocasa.com/testecommerce/service.asmx?wsdl

我需要向此SOAP API发出请求:https://ws.ocasa.com/testecommerce/service.asmx?wsdl

Both php curl and SoapClient are failing

php curl和SoapClient都失败了

With SoapClient I'm doing this (also tried with no options at all, and just the cache_wsdl part):

使用SoapClient我正在这样做(也尝试过根本没有选项,只有cache_wsdl部分):

$options = array(
    'cache_wsdl' => 0,
    'trace' => 1,
    'stream_context' => stream_context_create(array(
          'ssl' => array(
               'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
          )
    ))
);

$wsdl = 'https://ws.ocasa.com/testecommerce/service.asmx?wsdl';
$client = new \SoapClient( $wsdl, $options);

Giving me this error:

给我这个错误:

[SoapFault]
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://ws.ocasa.com/testecommerce/service.asmx?wsdl' : failed to load external entity "https:
//ws.ocasa.com/testecommerce/service.asmx?wsdl"

[SoapFault] SOAP-ERROR:解析WSDL:无法从“https://ws.ocasa.com/testecommerce/service.asmx?wsdl”加载:无法加载外部实体“https://ws.ocasa.com /testecommerce/service.asmx?wsdl”

With php curl I endend getting this error:

随着php curl我努力得到这个错误:

Unknown SSL protocol error in connection to ws.ocasa.com:443

与ws.ocasa.com:443相关的未知SSL协议错误

I cant get the page from the linux curl command line without a problem (from inside the VM, of course)

我无法从linux curl命令行获取页面而没有问题(当然,来自VM内部)

curl -I https://ws.ocasa.com/testecommerce/service.asmx?wsdl -v

The SSL connection is using TLS1.0 / RSA_3DES_EDE_CBC_SHA1

SSL连接使用TLS1.0 / RSA_3DES_EDE_CBC_SHA1

I tested adding

我测试了添加

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

and also tried adding the CA certs: (also tried adding them in the php.ini)

并尝试添加CA证书:(也尝试在php.ini中添加它们)

curl_setopt($ch, CURLOPT_CAINFO, '/vagrant/cacert.pem');

Something very strange is that I can curl some other https sites without problem like secure.php.net usgin php curl.

一些非常奇怪的是,我可以卷曲其他一些https网站没有问题,如secure.php.net usgin php curl。

Also, there is no "http" version available to get rid of the whole SSL problem.

此外,没有“http”版本可用于摆脱整个SSL问题。

Any ideas? I'm missing some dependency maybe? openssl is installed.

有任何想法吗?我可能错过了一些依赖吗? openssl已安装。

Thanks for your time.

谢谢你的时间。

1 个解决方案

#1


0  

Well, I kinda found a solution...

好吧,我有点找到了解决方案......

With curl (the CURLOPT_SSLVERSION makes the difference)

使用curl(CURLOPT_SSLVERSION有所不同)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $wsdl);
curl_setopt($ch, CURLOPT_POSTFIELDS,  $xml); // $xml is the envelope (string)
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_0);

I couldn't make SoapClient work, even with the SOAP_SSL_METHOD_TLS option. I'll mark it as resolved, but if some finds how to make it work with SoapClient, that would be the real answer.

即使使用SOAP_SSL_METHOD_TLS选项,我也无法使SoapClient工作。我会将其标记为已解决,但如果有人发现如何使其与SoapClient一起使用,那将是真正的答案。

This helped me out with making the request (not the ssl part)

这有助于我提出请求(而不是ssl部分)

#1


0  

Well, I kinda found a solution...

好吧,我有点找到了解决方案......

With curl (the CURLOPT_SSLVERSION makes the difference)

使用curl(CURLOPT_SSLVERSION有所不同)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $wsdl);
curl_setopt($ch, CURLOPT_POSTFIELDS,  $xml); // $xml is the envelope (string)
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_0);

I couldn't make SoapClient work, even with the SOAP_SSL_METHOD_TLS option. I'll mark it as resolved, but if some finds how to make it work with SoapClient, that would be the real answer.

即使使用SOAP_SSL_METHOD_TLS选项,我也无法使SoapClient工作。我会将其标记为已解决,但如果有人发现如何使其与SoapClient一起使用,那将是真正的答案。

This helped me out with making the request (not the ssl part)

这有助于我提出请求(而不是ssl部分)