web services - PHP : How to add keystore for SOAP https request
Get the solution ↓↓↓I am new in PHP .One of my PHP projects requires making a SOAP call to access a web service over HTTPS.
the service provider only gave us three file .jks, .p12. and .wsdl file.I tested the .wsdl file in SOAPUI tool it's working.I uploaded my .jks file in SOAPUI preference >ssl settings
then I wrote my PHP code
<?php
$wsdl = 'http://localhost/RbphpGateway/librb/RB_OLP_INITIATE_PAYMENT.wsdl';
try{
$clinet=new SoapClient($wsdl);
$ver =array("olpIdAlias"=>"****","merchantId"=>"***","merchantRefNum"=>"418934223","paymentAmount"=>"100","paymentCurrency"=>"USD","dynamicMerchantLandingURL"=>"","dynamicMerchantFailureURL"=>"");
$quates=$clinet->executeRB_OLP_INITIATE_PAYMENT($ver);
echo $quates->initiatePaymentDetailsRes->ibURL;
}catch(SoapFault $e){
echo $e->getMessage();
}
my Output is
Could not connect to host
as my knowledge for secure https connection, we need to add a keystore with the code.
can anybody give me hint how to add a certificate in PHP.? can i add my .jks file with php .?
Answer
Solution:
I doubt that the problem has something to do with https, especially when you describe that it works in SoupUI.
Which host is it that you can not connect to?
You refer to the wsdl file on localhost, and I suspect that the web service is located on a different host?
So is the probleme linked to localhost or to the ws-host?
Start ensuring that you have access to then wsdl-file and by adding options trace = 1 and exception = 0 when creating the$clinet
:
$clinet=new SoapClient($wsdl,array('trace' => 1, 'exception' => 0));
It allows you to examine the soap result further by using$client->__getLastRequest()
Answer
Solution:
i found solution . first i generated .pem file using openssl from .p12
$wsdl = dirname(__FILE__).'/librb/xxxxxx.wsdl';
$endpoint = 'https://pay.bnk.com/soap?service=payment';
$local_cert = dirname(__FILE__)."/key1.pem";
$passphrase = "*****";
$options = array(
'location' => $endpoint,
'keep_alive' => true,
'trace' => true,
'local_cert' => $local_cert,
'passphrase' => $passphrase,
'cache_wsdl' => WSDL_CACHE_NONE,
'trace' => 1, // traces let us look at the actual SOAP messages later
'exceptions' => 1 ,
);
try{
$client = new SoapClient($wsdl,$options)
} catch (SoapFault $E) {
echo $E->getMessage();
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: failed to create image decoder with message 'unimplemented'
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.