SOAP request and response in PHP - php

I'm absolutely new in this question. I need to get Token from SOAP request in PHP.
Request
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:GetToken>
<tem:WebChanelID>8</tem:WebChanelID>
<tem:AccessCode>444555</tem:AccessCode>
</tem:GetToken>
</soap:Body>
</soap:Envelope>
Server https://hma.ecvi.ru/service/webform.wsdl.php

What i do wrong here?
$soapUrl = "https://hma.ecvi.ru/service/webform.wsdl.php";
$xml_post_string = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:GetToken>
<tem:WebChanelID>631</tem:WebChanelID>
<tem:AccessCode>989</tem:AccessCode>
</tem:GetToken>
</soap:Body>
</soap:Envelope>';
$headers = array(
"POST /package/package_1.3/packageservices.asmx HTTP/1.1",
"Host: hma.ecvi.ru",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($xml_post_string)
);
$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
$parser = simplexml_load_string($response2);
echo $parser;

Related

Getting Blank response when i am executing my curl php with request with wsdl and endpoint url

Please help me, getting Blank response when i am executing my curl php with request and wsdl ,endpoint url.
Here is my code:
//end point url
$e_url="https://tmcrmportal.inservices.tatamotors.com/home/B2C/com.eibus.web.soa
p.Gateway.wcp?organization=o=B2C;cn=cordys,cn=cbop,o=tatamotors.com";
//wsdl
$wsdl="WSDL";
//$curl = curl_init($e_url);
//request
$xml_post_string = '<?xml version="1.0"?>
<SOAP:Envelope xmlns:SOAP=\\"http://schemas.xmlsoap.org/soap/envelope/\\">
<SOAP:Header>
<wsse:Security xmlns:wsse=\\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\\">
<wsse:UsernameToken xmlns:wsse=\\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\\">
<wsse:Username>username</wsse:Username>
<wsse:Password>pwd</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP:Header>
<SOAP:Body>
<samlp:Request IssueInstant=\\"2004-12-05T09:21:59Z\\" MajorVersion=\\"1\\" MinorVersion=\\"1\\" RequestID=\\"456789\\" xmlns:samlp=\\"urn:oasis:names:tc:SAML:1.0:protocol\\">
<samlp:AuthenticationQuery>
<saml:Subject xmlns:saml=\\"urn:oasis:names:tc:SAML:1.0:assertion\\">
<saml:NameIdentifier Format=\\"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified\\">username</saml:NameIdentifier>
</saml:Subject>
</samlp:AuthenticationQuery>
</samlp:Request>
</SOAP:Body>
</SOAP:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($xml_post_string),
);
$ch = curl_init("ENDPOINTURL");
curl_setopt($ch, CURLOPT_URL, $wsdl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
if(curl_exec($ch) === false) {
$err = 'Curl error: ' . curl_error($ch);
print $err;
curl_close($ch);
} else {
$response = curl_exec($ch);
print $response.'Operation completed without any errors';
curl_close($ch);
}
I guess that you're actually getting 500 error, but error output was disabled in your php configuration. If so, check in your phpinfo() that you have curl module installed. Please avoid showing your real credentials when asking a question for security reasons.

soap request to barclays soap api payments using php curl

I have given a task of posting a payment using Barclays SOAP API Payments. After reading the document, they are giving a TEST url for the soap request and also test Credit Card Number. I have used below but it is not doing NOTHING. No response or NOTHING is received at all.
$requestXML = "<?xml version='1.0'?>
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<soap:Body>
<ns1:authorise xmlns:ns1='http://payment.services.adyen.com'>
<ns1:paymentRequest>
<amount xmlns='http://payment.services.adyen.com'>
<currency xmlns='http://common.services.adyen.com'>GBP</currency>
<value xmlns='http://common.services.adyen.com'>67</value>
</amount>
<card xmlns='http://payment.services.adyen.com'>
<cvc304</cvc>
<expiryMonth>03</expiryMonth>
<expiryYear>2019</expiryYear>
<holderName>Owais</holderName>
<number>55554444333331111</number>
</card>
<merchantAccount xmlns='http://payment.services.adyen.com'>owaiskhan772</merchantAccount>
<reference xmlns='http://payment.services.adyen.com'>CPD-1232</reference>
<shopperEmail xmlns='http://payment.services.adyen.com'>owaiskhan772#gmail.com</shopperEmail>
<shopperReference xmlns='http://payment.services.adyen.com'>2843</shopperReference>
</ns1:paymentRequest>
</ns1:authorise>
</soap:Body>
</soap:Envelope>";
$soapUrl = "https://pal-test.barclaycardsmartpay.com/pal/servlet/soap/Payment"; // test url
$soapUser = ""; // username
$soapPassword = ""; // password
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: https://pal-test.barclaycardsmartpay.com/pal/servlet/soap/Payment",
"Content-length: ".strlen($requestXML),
); //SOAPAction: your op URL
$url = $soapUrl;
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXML); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
I AM NOT GETTING ANYTHING FROM IT. WHAT'S WRONG WITH IT. Thanks

PHP XML request to SOAP WebService

Sorry if i am asking something that was already discussed here but all my combinations that i tryed are not working. I am not PHP developer but i am trying create PHP sample that will send request to my SOAP asp.net webservice and to echo the response.
I am trying to use the following PHP code:
$soapUrl = "https://test-api.xxxx.xx/reseller.asmx?op=loginXML";
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body><loginXML xmlns="https://test-api.zemi.mk/"><acckey>adsdsad</acckey><password>pass</password></loginXML></soap12:Body></soap12:Envelope>';
$headers = array(
"POST /reseller.asmx HTTP/1.1",
"Host: test-api.*****.**",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($xml_post_string)
);
$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
$parser = simplexml_load_string($response2);
echo $parser;
But it does not work.
What i am seeing then i am trying to execute is:
$soapUrl = "https://test-api.++++.++/reseller.asmx?op=loginXML"; $xml_post_string = 'adsdsadpass'; $headers = array( "POST /reseller.asmx HTTP/1.1", "Host: test-api.++++.++", "Content-Type: application/soap+xml; charset=utf-8", "Content-Length: ".strlen($xml_post_string) ); $url = $soapUrl; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); $response1 = str_replace("","",$response); $response2 = str_replace("","",$response1); $parser = simplexml_load_string($response2); echo $parser;
Can u help me what i am doing wrong.
Thanks

Sending XML using Curl post to a webservice

I am trying to send a XML script to a webserver to retrieve an authentication token, i would like some help with that. At the moment with my code i think it is connecting but it returns only the wsdl file in text format on the screen.
I would like to receive the autentication token.
My code:
<?php
$xml_data = '
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://dpd.com/common/service/types/LoginService/2.0">
<soapenv:Header/>
<soapenv:Body>
<ns:getAuth>
<delisId>id</delisId>
<password>password</password>
<messageLanguage>nl_NL</messageLanguage>
</ns:getAuth>
</soapenv:Body>
<soapenv:Envelope>
';
$headers = array(
"POST HTTP/1.1",
"Host: hostname",
"Content-type: application/soap+xml; charset=\"utf-8\"",
"SOAPAction: \"http://dpd.com/common/service/LoginService/2.0/getAuth\"",
"Content-length: ".strlen($xml_data)
);
$url = 'https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$err = curl_error($ch);
print_r($output);
print_r($err);
curl_close($ch);
?>
The WSDL file is in the link below:
https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl
Here you go, works a treat:
$xml_data = '
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://dpd.com/common/service/types/LoginService/2.0">
<soapenv:Header/>
<soapenv:Body>
<ns:getAuth>
<delisId>id</delisId>
<password>password</password>
<messageLanguage>nl_NL</messageLanguage>
</ns:getAuth>
</soapenv:Body>
<soapenv:Envelope>
';
$headers = array(
"POST HTTP/1.1",
"Host: hostname",
"Content-type: application/soap+xml; charset=\"utf-8\"",
"SOAPAction: \"http://dpd.com/common/service/LoginService/2.0/getAuth\"",
"Content-length: ".strlen($xml_data)
);
$url = 'https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //Don't verify ssl certificate
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
$reply = curl_exec($ch);
// Represents an element in an XML document.
$xmli = new SimpleXMLElement($reply);
// prints the XML response
print_r($reply);
// prints the XML object
print_r($xmli);
I've included the SimpleXMLElement class incase you wanted to access the response data as an object.

Calling a SOAP method with PHP with curl functions

i want to try calling soap method in php with curl function but it showing one warning
Warning: curl_setopt() [function.curl-setopt]: Invalid curl configuration option in /home/bestbus/public_html/apitest.php on line 26
<?
$xml_data ='<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:rsr="http://webservices.foxfireindia.com/RSRSAPI">
<soap:Header>
<rsr:LinkCredentials>
<!--Optional:-->
<rsr:Login>***main</rsr:Login>
<!--Optional:-->
<rsr:Password>****#3api</rsr:Password>
</rsr:LinkCredentials>
</soap:Header>
<soap:Body>
<rsr:Login>
<!--Optional:-->
<rsr:userName>***main</rsr:userName>
<!--Optional:-->
<rsr:password>****#3api</rsr:password>
</rsr:Login>
</soap:Body>
</soap:Envelope>';
$URL = "http://115.254.89.1:8090/RSRS_APITest/RSRSAPI.asmx?wsdl";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
print_r($output);
curl_close($ch);
?>
According the manual, the only valid values for CURLOPT_SSL_VERIFYHOST are 1 or 2, and the use of 1 has been removed in cURL 7.28.1
1 to check the existence of a common name in the SSL peer certificate.
2 to check the existence of a common name and also verify that it matches the hostname provided. In production environments the value of this option should be kept at 2 (default value).
Try this one:
<?php
$xml_data = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:rsr="http://webservices.foxfireindia.com/RSRSAPI">
<soap:Header>
<rsr:LinkCredentials>
<!--Optional:-->
<rsr:Login>***main</rsr:Login>
<!--Optional:-->
<rsr:Password>****#3api</rsr:Password>
</rsr:LinkCredentials>
</soap:Header>
<soap:Body>
<rsr:Login>
<!--Optional:-->
<rsr:userName>***main</rsr:userName>
<!--Optional:-->
<rsr:password>****#3api</rsr:password>
</rsr:Login>
</soap:Body>
</soap:Envelope>';
$URL = "http://115.254.89.1:8090/RSRS_APITest/RSRSAPI.asmx?wsdl";
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($tresc),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$output = curl_exec($ch);
print_r($output);
curl_close($ch);
?>
Try replacing
curl_setopt($ch, CURLOPT_MUTE, 1);
with
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
because as of documentation http://php.net/manual/en/function.curl-setopt.php CURLOPT_MUTE is removed in cURL 7.15.5

Categories