Curl SOAP POST Request PHP 5.5.9 - php

I would like someone with experience in SOAP requests with Curl and PHP to assist me. I have the situation where I am making SOAP PHP requests from my PHP app to remote server which is working great from my local server (PHP 7.0 , Curl 7.47 )
The problem is when I deploy the app on my server with PHP 5.5.9 and curl 7.50 , with completely same code, I get empty response from the Curl call. Here is the part of the code:
$xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tcit="urn:microsoft-dynamics-schemas/page/tcitems">';
$xml_post_string .= '<soapenv:Header/>';
$xml_post_string .= '<soapenv:Body>';
$xml_post_string .= '<tcit:ReadMultiple>';
$xml_post_string .= '</tcit:ReadMultiple>';
$xml_post_string .= '</soapenv:Body>';
$xml_post_string .= '</soapenv:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: `here goes my remote url which I am calling`"
);
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
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, 300);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
Actually I get empty string as a response, but when I debugged I saw that problem is 401 request (Something with auth?). Anyway the script is working perfectly from my localhost, so I suppose it is related to some version incopatibility on remote Server. Let me hear your thoughts and what do you think in this configuration can be the problem.
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); (this return 401)
$curl_errno= curl_errno($ch); (this returns 0)

Related

SOAP request via CURL php symfony

in one of my projects i need to send SOAP request to remote servers. For doing so i am using below script (using CURL). For some reason i am not getting any response if i ran below script.
If i try sending requests via SOAP UI, all works just like it should be. When replicating functionality in php, i get no response at all and not able to identify what the problem is.
public function sendRequestAction ($cntiin) {
$userid = 'XXXXX';
$clientid = 'YYYYY';
$password = 'Test_Test';
$urltest = 'https://y.fake.url/testServices/PersonDetailsImplService';
//variable defenition
$identifier = '700521700054';
$xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:data="http://data.fake.url.test.net">
<soapenv:Header>
<userId>3d4f80d7</userId>
</soapenv:Header>
<soapenv:Body>
<data:getPerson>
<!--Optional:-->
<iin>' . $identifier . '</iin>
<!--Optional:-->
<consentConfirmed>true</consentConfirmed>
</data:getPerson>
</soapenv:Body>
</soapenv:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: https://y.fake.url/gbdServices/PersonDetailsImplService",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
// PHP cURL for https connection with auth
$url = $urltest .'?wsdl';
$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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERPWD, $clientid.":".$password); // 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, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($response);
}
When sending requests via SOAP UI there is Basic Auth with login and password, which i believe is accounted for above. Still no results
I went thruogh numerous articles including:
this one and this one and many others but still not sure why not working, so any feedback will be highly appriciated.

Handling carriage return in soap request

I am writing code in PHP to send a soap request using curl. In the soap request I have to send data of a text file which have many Carriage Returns. I have tried sending "carriage return" using \n, \r, \r\n, chr(13) etc but all of these are giving the following error from server
Lines in the data sent should be delimited by single CR characters only. This file appears to be using LF as a delimiter.
Following is my Soap request. I am developing in linux and sending request to windows server.
<?php
$submitFileTxt .= "Line1 Text"."\r";
$submitFileTxt .= "Line2 Text"."\r";
$submitFIleTxt .= "Test,Test,Test"."\r";
$submitFIleTxt .= "Testtext,Testtext,Testtext"."\r";
$wsdl = "somewsdlurl?wsdl";
$local_cert = "certificate file path";
$password = '';
$xml_post_string = "<s:Envelope xmlns:a='http://www.w3.org/2005/08/addressing' xmlns:s='http://www.w3.org/2003/05/soap-envelope'>
<s:Header>
<a:Action s:mustUnderstand='1'>Data submit method</a:Action>
</s:Header>
<s:Body>
<Submit>
<data xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<OutputFileBody>{$submitFIleTxt}</OutputFileBody>
<OutputFilename>Some file name</OutputFilename>
</data>
</Submit>
</s:Body>
</s:Envelope>";
$headers = array(
"Content-type: application/soap+xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Content-length: ".strlen($xml_post_string),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $wsdl);
curl_setopt($ch, CURLOPT_SSLCERTTYPE, "pem");
curl_setopt($ch, CURLOPT_SSLCERT, $local_cert);
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $password);
curl_setopt($ch, CURLOPT_SSLKEY, $local_cert);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
You can use 
 in place oo \r and
in place of \n.

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

Curl xml Response in Php

i need to post Data in Xml to a server but whnen i use a basic curl post i have a redirect page to the curl url , but when i use something like postman it works just find , I even tried the code generated by postman and i got the same results (redirect)
here is my curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "URL");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ["SAMLResponse"=> $xml]);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "content-type: application/x-www-form-urlencoded";
$headers[] = "authorization: Basic CODE";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = (curl_exec($ch));

Soap: <faultstring> 11|Session|</faultstring>

I am getting faultcode error with soap as per below while using soap request with php.
<soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring> 11|Session|</faultstring></soap:Fault></soap:Body>
Kindly suggest about this error.
I am using below code in PHP :
$request = '<soapenv:Envelope xmlns:soapenv="..>
<soapenv:Header xmlns:add="http://www.w3.org/2005/08/addressing">
<MessageID>...
<oas:Security xmlns:..">
<oas:UsernameToken oas1:Id="UsernameToken-1">
...
</oas:UsernameToken>
</oas:Security>
<awsse:Session TransactionStatusCode="Start" xmlns:awsse="http://xml.amadeus.com/2010/06/Session_v3"/>
</soapenv:Header>
<soapenv:Body>
....
</soapenv:Body>
</soapenv:Envelope>';
$soapaction = "..";
$url = "..";
$headers = array(
"Accept-Encoding: gzip,deflate",
"Content-Type: text/xml;charset=UTF-8",
"SOAPAction: $soapaction",
"Connection: Keep-Alive",
"Host: nodeD1.test.com",
"User-Agent: ".$_SERVER['HTTP_USER_AGENT'],
"Content-length: ".strlen($request)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_ENCODING, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
$response = curl_exec($ch);
I have tried with $client->__doRequest method with SoapClient class.
Usually this causes from authentication issue. The request which you constructed could not reach the resources on target because of incorrect authentication or header data. please try this it will work.
-You should check all parameters in <soapenv:Header>.
-Username in the UserToken might be missing or incorrect.

Categories