且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-21 21:57:25

我在肥皂呼叫中使用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
    )
);

在我的证书中有2个部分.证书和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.

希望这会对您有所帮助.

Hope this will help you.