如何在 PHP 中使用 SSL 证书发送 SOAP 请求?

how to send SOAP request with SSL certificate in PHP?(如何在 PHP 中使用 SSL 证书发送 SOAP 请求?)
本文介绍了如何在 PHP 中使用 SSL 证书发送 SOAP 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试发送带有 DER 证书的 SOAP - PHP 请求(这意味着该证书没有私钥)但没有成功.

I'm trying to send a SOAP - PHP request with a DER certificate (that means the certificate don't have a privateKey) but no success.

$local_cert = FULL_PATH_TO_MY_CERT;

   $client = new SoapClient($wsdl, array(
                'local_cert' => $local_cert,
                'trace' => 1,
                'exceptions' => 1,
                'soap_version' => SOAP_1_1,
                'encoding' => 'ISO-8859-1',
                'compression' => (SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP),
                'location' => 'https://webserviceurl:port/ws/servlet/ws'
            ));

只有我收到此错误:

警告 (2): SoapClient::SoapClient() [soapclient.soapclient]: 无法设置私钥文件 `PATHTOMYLOCALCERT' [APPVendorWebServicesMyWS.php, line 206]

Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: Unable to set private key file `PATHTOMYLOCALCERT' [APPVendorWebServicesMyWS.php, line 206]

警告 (2):SoapClient::SoapClient() [soapclient.soapclient]:未能创建 SSL 句柄 [APPVendorWebServicesMyWS.php,第 206 行]

Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: failed to create an SSL handle [APPVendorWebServicesMyWS.php, line 206]

警告 (2):SoapClient::SoapClient() [soapclient.soapclient]:无法启用加密 [APPVendorWebServicesMyWS.php,第 206 行]

Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: Failed to enable crypto [APPVendorWebServicesMyWS.php, line 206]

警告(2):SoapClient::SoapClient(https://webserviceurl:port/ws/servlet/ws?wsdl) [soapclient.soapclient]: failed to open stream: operation failed [APPVendorWebServicesMyWS.php,第 206 行]

Warning (2): SoapClient::SoapClient(https://webserviceurl:port/ws/servlet/ws?wsdl) [soapclient.soapclient]: failed to open stream: operation failed [APPVendorWebServicesMyWS.php, line 206]

警告(2):SoapClient::SoapClient() [soapclient.soapclient]:I/O 警告:无法加载外部实体https://webserviceurl:port/ws/servlet/ws?wsdl"[APPVendorWebServicesMyWS.php,第 206 行]

Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "https://webserviceurl:port/ws/servlet/ws?wsdl" [APPVendorWebServicesMyWS.php, line 206]

但我发现了一个小技巧(在 php.net 中)使用函数 file_get_contents($local_cert);错误消失了.

but I've found a little trick (in php.net) using the function file_get_contents($local_cert); the errors are gone.

但是出现了一个新的错误.

But a new error come from.

结果:string(773)错误读取前缀:Action.Execute"

Result : string(773) "Error reading prefix:Action.Execute"

我的意思是......上面的这个错误......来自WebService?因为它无法通过我的请求进行身份验证?

What I mean is... this error above... is comming from the WebService? because it cannot authenticate with my request?

谢谢大家.(感谢您的回答)

Thanks everybody. (appreciate your answers)

推荐答案

我在soap调用中使用SSL证书.

I'm using SSL certificate in my soap call.

就我而言,我在服务器上为 wsdllocal_cert 提供绝对路径我已经在我的班级中定义了这些.请注意,我使用的是 .pem 格式的证书.

In My case I'm giving absolute path on my server for wsdl and for local_cert I've already defined those in my class. Please note that I'm using my certificate in .pem format.

public $local_cert = "/var/www/.../webroot/cert.pem";
public $wsdl = "/var/www/.../webroot/my_wsdl.wsdl";

$this->client = new SoapClient($this->wsdl, array(
        "trace"         => 1, 
        "exceptions"    => true, 
        "local_cert"    => $this->local_cert, 
        "uri"           => "urn:xmethods-delayed-quotes",
        "style"         => SOAP_RPC,
        "use"           => SOAP_ENCODED,
        "soap_version"  => SOAP_1_2 ,
        "location"      => $this->location
    )
);

在我的证书中有两部分.证书和 RSA 私钥.

In my certificate there are 2 parts. Certificate and RSA Private Key.

(1)-----BEGIN CERTIFICATE-----
MIIFjzCC....
....
-----END CERTIFICATE-----
(2)-----BEGIN RSA PRIVATE KEY-----
MIIEpAI....
....
ww==
-----END RSA PRIVATE KEY----

最重要的是,您应该使用 https 链接进行肥皂调用.这对我来说很好用.

And most important you should use https link for making a soap call. This is working fine for me.

希望对你有帮助.

这篇关于如何在 PHP 中使用 SSL 证书发送 SOAP 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)