我需要连接到服务器环境,并且所说的选项是:
网址: https://servicos.portaldasfinancas.gov.pt:701/sgdtws/documentosTransporte
考虑到这一点,我需要向该主机发送XML并从中接收响应。我已经尝试过使用SoapClient()而没有任何成功,现在我正在尝试使用CURL。
$xml = 'my xml...';
$soap = curl_init();
$soapAction = 'https://servicos.portaldasfinancas.gov.pt/sgdtws/documentosTransporte/';
$action = 'https://servicos.portaldasfinancas.gov.pt:701/sgdtws/documentosTransporte';
curl_setopt($soap, CURLOPT_RETURNTRANSFER, true);
curl_setopt($soap, CURLOPT_HTTPHEADER, array(
'Content-Type:text/xml;Charset=UTF-8',
'Accept: text/xml',
'Cache-Control: no-cache',
'SoapAction=' . $soapAction
));
curl_setopt($soap, CURLOPT_URL, $action);
curl_setopt($soap, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($soap, CURLOPT_VERBOSE, TRUE);
curl_setopt($soap, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($soap, CURLOPT_POST, 1);
curl_setopt($soap, CURLOPT_POSTFIELDS, $xml);
curl_setopt($soap, CURLOPT_SSLKEY, 'TesteWebServices.pfx');
curl_setopt($soap, CURLOPT_SSLKEYPASSWD, 'TESTEwebservice');
$response = curl_exec($soap);
if(curl_errno($soap)){
echo 'Curl error: ' . curl_error($soap);
return;
}
目前我收到以下错误:
卷曲错误:SSL证书问题:自签名证书 证书链
如果我像这样改变CURL的一些变量:
curl_setopt($soap, CURLOPT_SSLCERT, 'pfxCert.pem');
curl_setopt($soap, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($soap, CURLOPT_SSLCERTPASSWD, 'TESTEwebservice');
curl_setopt($soap, CURLOPT_SSLKEY, 'pfxKey.pem');
curl_setopt($soap, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($soap, CURLOPT_SSLKEYPASSWD, 'okgo');
然后我收到了不同的错误。
卷曲错误:无法使用客户端证书(未找到密钥或错误 传递短语?)
虽然我100%确定两个密码都是正确的。
最后,文件pfxCert.pem
和pfxKey.pem
来自TesteWebServices.pfx
这样:
openssl pkcs12 -in TesteWebServices.pfx -nocerts -out pfxKey.pem
openssl pkcs12 -in TesteWebServices.pfx -clcerts -nokeys -out pfxCert.pem