2015-03-03 42 views
1

我面臨調用soap函數的問題。我收到錯誤「無法連接到主機」。我使用的是「wamp server」,「php version 5.3.13」和「apache version 2.2.22」。使用客戶端證書調用soap函數

我有.p12格式的客戶端證書,wsdl文件在本地系統上可用,我已經使用soapUI-m-snapshot測試了soap調用。它工作正常!但是,當我嘗試與「SoapClient」變得「無法連接到主機」相同。 我使用以下肥皂選項

$soapclient_options = array(); 
$soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE'; 
$soapclient_options['local_cert'] = $certificatePath; 
$soapclient_options['passphrase'] = $api_certificate_passphrase; 
$soapclient_options['trace'] = true; 
$soapclient_options['connection_timeout'] = 15; 
$soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3'; 
$soapclient_options['location'] = 'api location'; 

$client = new SoapClient($wsdl_path, $soapclient_options); 
$client->__setLocation($soapclient_options['location']); 

我是在做錯誤的方式的東西嗎? 有人請提前告訴我,並多謝。

回答

1

PHP Soap客戶端只接受pem證書。您可以使用以下隱藏證書:

openssl pkcs12 -in in.p12 -out out.pem -nodes -clcerts 
+0

感謝格雷格,我找到了同樣的地方,爲我工作。 – 2015-03-16 13:00:24

+0

您能否將我的答案標記爲將來參考的正確答案。謝謝。 – Greg 2015-03-16 17:02:55

+0

哦!我忘記了,我是新來的。 – 2015-03-16 18:11:07

-1

需要額外的代碼才能使用PHP 5.6版本。

$soapclient_options['stream_context'] = stream_context_create(
      array(
       'ssl' => array(
        'verify_peer' => false, 
        'verify_peer_name' => false, 
       ) 
      ) 
    ); 
+0

請不要這樣做!它會使你的連接變得不安全,容易受到中間人攻擊!它使您的客戶接受任何證書,而不僅僅是你的! – Greg 2016-12-17 17:36:52

+0

這是因爲您的證書可能是自簽名的,未經某些全球機構(證書頒發機構)驗證。正確的解決方案是擁有服務器證書並僅信任該證書。更多這裏(例如捲曲,但它也適用於所有流 - file_get_contents,肥皂等):http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access -https-ssltls-protected-sites/ – Greg 2016-12-17 17:42:28

+0

感謝@Greg我不使用此解決方案。我已經轉移到了不同​​的身份驗證系統。 – 2016-12-19 05:17:54