gpt4 book ai didi

php - 在 PHP 中进行 SOAP 调用并设置 SSL 版本

转载 作者:IT王子 更新时间:2023-10-29 00:12:46 24 4
gpt4 key购买 nike

我制作了几个使用外部 WSDL 的脚本。我遇到过一个我必须集成到我们的系统中但无法开始工作的情况。我已经尝试了一个星期,但没有任何结果。

脚本已经在创建构造函数时失败了:

$client = new SoapClient("https://webtjener09.kred.no/TestWebservice/OppdragServiceSoapHttpPort?WSDL");

给出错误:

PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://webtjener09.kred.no/TestWebservice/OppdragServiceSoapHttpPort?WSDL' : failed to load external entity "https://webtjener09.kred.no/TestWebservice/OppdragServiceSoapHttpPort?WSDL"

我确实安装了 openssl 并使用 PHP,请记住,我已经通过 SSL 对其他 WSDL 进行了其他有效的 SOAP 调用。我发现我也不能用证书解决这个问题,因为它已经在构造函数中失败了。

但是:我尝试用openssl命令行连接到远程服务器,这个命令也失败了:

openssl s_client -connect webtjener09.kred.no:443 -state

但后来我尝试将其强制为 SSL3,它运行良好,如下所示:

openssl s_client -ssl3 -connect webtjener09.kred.no:443 -state

所以这让我想到我必须匹配远程服务器的 SSL 版本。为了仔细检查,我还尝试通过 PHP 建立 cURL 连接,但它失败了,直到我像这样添加强制 SSL 版本:

curl_setopt($ch, CURLOPT_SSLVERSION, 3);

将 CURLOPT_SSLVERSION 添加到 cURL 连接使其正常。然后是我问题的根源:

如何强制 PHP soap 构造函数/调用也使用 SSL3。在我看来,这必须是解决方案。但我一直无法找到如何将 PHP SOAP 函数设置为仅使用 SSL3。由于命令行 -openssl- 和 PHP cURL 都在强制使用 SSL3 的情况下工作,那么我假设我的 SOAP 函数会发生同样的事情吗?

输入,好吗?

(使用 Ubuntu Linux,PHP 5.3.3)

最佳答案

我有同样的问题,下面的包装器解决了它(我不得不强制使用 SSL2)

class StupidWrapperForOracleServer extends SoapClient {
protected function callCurl($url, $data, $action) {
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml", 'SOAPAction: "' . $action . '"'));
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($handle, CURLOPT_SSLVERSION, 2);
$response = curl_exec($handle);
if (empty($response)) {
throw new SoapFault('CURL error: '.curl_error($handle),curl_errno($handle));
}
curl_close($handle);
return $response;
}

public function __doRequest($request,$location,$action,$version,$one_way = 0) {
return $this->callCurl($location, $request, $action);
}
}

顺便说一句。如果在下载 WSDL 文件部分失败,则手动下载 WSDL(例如使用 curl),并在本地使用该文件。恕我直言,在 WSDL 下载阶段不会调用 __doRequest。

file_put_contents(dirname(__FILE__) .'/Server.wsdl',get_wsdl()); //get_wsdl uses the same wrapper as above
$oWS = new StupidWrapperForOracleServer(dirname(__FILE__) .'/Server.wsdl',array('trace'=>1,'cache_wsdl'=>0));

关于php - 在 PHP 中进行 SOAP 调用并设置 SSL 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4721788/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com