I want to do this payment getway request by sending this xml .
<?xml version="1.0" encoding="UTF-8"?>
<COBROAIRLINES>
<paymentService>
<id_company>0000</id_company>
<id_branch>5</id_branch>
<country>MEX</country>
<user>USUARIO</user>
<password>DE3C9FEF064F1459C30C0E7B</password>
<merchant>00000</merchant>
<reference>123pba</reference>
<tp_operation>12</tp_operation>
<creditCardType>V/MC</creditCardType>
<creditCardName>NOMBRE TH</creditCardName>
<creditCardNumber>AF3992EE603B743FC70D0D71F858C63C</creditCardNumber>
<creditCardExpMonth>AB3D</creditCardExpMonth>
<creditCardExpYear>AA3E</creditCardExpYear>
<creditCardCVV>291</creditCardCVV>
<initialDeferment>00</initialDeferment>
<numberOfPayments>06</numberOfPayments>
<planType>03</planType>
</paymentService>
<transaction>
<transactionTS>2008/01/01 10:00:00</transactionTS>
<currency>MXN</currency>
<orderAmount>1000</orderAmount>
<orderTotalTickets>1</orderTotalTickets>
<orderPromo>0</orderPromo>
<orderSource>000</orderSource>
<sdos>1</sdos>
</transaction>
<passengerFlight>
<passengerName>Juan Perez</passengerName>
<passengerTicketAmount>1000</passengerTicketAmount>
<passengerFrequentFlierNumber>96321</passengerFrequentFlierNumber>
<flightFare>A</flightFare>
<flightRoundTrip>0</flightRoundTrip>
<flightOriginCity>MEX</flightOriginCity>
<flightOriginCountry>MEX</flightOriginCountry>
<flightDestinationCity>TKY</flightDestinationCity>
<flightDestinationCountry>JAP</flightDestinationCountry>
<flightDaysTillDeparture>1</flightDaysTillDeparture>
<flightLayovers>0</flightLayovers>
</passengerFlight>
<userSalutation>Ing.</userSalutation>
<userName>Juan Perez</userName>
<userStreet>Heriberto Frias 1527</userStreet>
<userNeighborhood>Del Valle</userNeighborhood>
Confidential 13 de 25 Airlines Payment Iv6.0
<userCity>Mexico</userCity>
<userState>DF</userState>
<userZipCode>03100</userZipCode>
<userCountry>Mexico</userCountry>
<userPhone>5554425700</userPhone>
<userPhone2>5512345678</userPhone2>
<userEMail>correo#correo.com.mx</userEMail>
<userLogin>prueba</userLogin>
<userReturnCustomer>0</userReturnCustomer>
<billingName>Juan Perez</billingName>
<billingStreet>Corregidora</billingStreet>
<billingHouseNumber>92</billingHouseNumber>
<billingHouseNumberInt>1</billingHouseNumberInt>
<billingNeighborhood>Miguel Hidalgo</billingNeighborhood>
<billingMunicipality>Tlalpan</billingMunicipality>
<billingCity>Mexico</billingCity>
<billingState>DF</billingState>
<billingZipCode>14260</billingZipCode>
<billingCountry>Mexico</billingCountry>
<billingPhone>5515009000</billingPhone>
<billingPhone2>5515009020</billingPhone2>
<billingEMail>correo#correo.com</billingEMail>
<browserSessionID>org.apache.catalina.session.Sta...</browserSessionID>
<browserHostName>172.0.0.1</browserHostName>
<browserAccept>image/gif</browserAccept>
<browserAcceptEncoding>gzip, deflate</browserAcceptEncoding>
<browserAcceptCharset>ISO-8859-1,utf-8;q=0.7,*;q=0.7 </browserAcceptCharset>
<browserID>Mozilla/4.0 (compatible; MSIE 5.5)</browserID>
<browserIDLanguageCode>en-us,en;q=0.5</browserIDLanguageCode>
<browserCookie>CL=null</browserCookie>
<browserIP>172.452.16.23</browserIP>
<browserReferer>http://www.cualquiera.com</browserReferer>
<browserConnection>keep-alive</browserConnection>
<javascriptData> TF1;014;5;7;18068;6%2C0%2C6001%2C18000;....</javascriptData>
<customField1>ABCDEF</customField1>
<customField2></customField2>
<customField3></customField3>
<customField4></customField4>
<customField5></customField5>
</COBROAIRLINES>
the url of payment getway is https://dev.mitec.com.mx/wscobroSdos/CobroAirlines/?xml=
in documentation of payment getway , they have given xml=xml file content .
so basically i dont know it is GET or POST , but with no of charachter in xml i am assuming it will be POST.
so what i have tried ,
$xmldatafile="payment.xml";
$xmlData = file_get_contents($xmldatafile);
$URL = "https://dev.mitec.com.mx/wscobroSdos/CobroAirlines?xml=";
$ch = curl_init();
// curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_URL, $URL);
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_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $output = curl_exec($ch);
if(curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
and it is giving me this response don't know why what can i do ?
i think this is the paymentgetway site http://www.centrodepagos.com.mx/cdpweb/descargas.htm
the response m getting is :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CENTEROFPAYMENTS>
<reference></reference>
<response>error</response>
<foliocpagos></foliocpagos>
<auth></auth>
<cd_response></cd_response>
<cd_error>01</cd_error>
<nb_error>El xml enviado no corresponde a ningun modelo</nb_error>
<time>05:02:44</time>
<date>28/02/2012</date>
<voucher></voucher>
</CENTEROFPAYMENTS>
The same api also tried in django python , which is my ultimate goal.
import pycurl
ncServerURL='https://dev.mitec.com.mx/wscobroSdos/CobroAirlines?xml='
binaryptr = open('payment.xml','rb').read()
c = pycurl.Curl()
c.setopt(pycurl.URL, ncServerURL)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.HTTPHEADER, ["Content-type: text/xml"])
# c.setopt(c.URL, ncServerURL + '?xml=' + binaryptr)
# c.setopt(pycurl.TIMEOUT, ncServerMaxTime)
# c.setopt(pycurl.CONNECTTIMEOUT, ncServerMaxTime)
c.setopt(pycurl.NOSIGNAL, 1) # disable signals, curl will be using other means besides signals to timeout.
c.setopt(pycurl.POSTFIELDS, binaryptr)
import StringIO
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
ncServerData = b.getvalue()
print ncServerData
the response m getting is :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CENTEROFPAYMENTS>
<reference></reference>
<response>error</response>
<foliocpagos></foliocpagos>
<auth></auth>
<cd_response></cd_response>
<cd_error>01</cd_error>
<nb_error>El xml enviado no corresponde a ningun modelo</nb_error>
<time>05:02:44</time>
<date>28/02/2012</date>
<voucher></voucher>
</CENTEROFPAYMENTS>
tried with urllib2
import urllib2
import urllib
binaryptr = open('payment.xml','rb').read()
data = binaryptr
headers = {
'Content-Type': 'application/soap+xml; charset=utf-8'
}
req = urllib2.Request('https://dev.mitec.com.mx/wscobroSdos/CobroAirlines?xml=', data, headers)
response = urllib2.urlopen(req)
the_page = response.read()
print the_page
Got the same error as above.
It looks like it wants the xml in the url, rather than the body. This is pretty bad design, but try appending it to ?xml=
$URL = "https://dev.mitec.com.mx/wscobroSdos/CobroAirlines/?xml=" . $xmlData;
Related
I want to configure an api of soap with php, following the xml is used for the api, but its not responding, please help me to recover this problem
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fram="http://framework.zend.com">
<soapenv:Header/>
<soapenv:Body>
<fram:getCountries>
<securityInfo>
<userName>username</userName>
<password>password</password>
<agentCode>code</agentCode>
<lang>en</lang>
</securityInfo>
</fram:getCountries>
</soapenv:Body>
</soapenv:Envelope>
The below showing the php code I used to call xml. But I didnt get any response to my php code, but the xml is correct, I have asked to the provider they told me the xml is correct but my php code is not correct. I dont what I do to solve this problem :(
<?php
$soapUrl = "http://testapi.roombookpro.com/en/soap/index?wsdl"; // asmx URL of WSDL
$soapUser = "username"; // username
$soapPassword = "password"; // password
// xml post structure
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fram="http://framework.zend.com">
<soapenv:Header/>
<soapenv:Body>
<fram:getCountries>
<securityInfo>
<!-- You may enter the following 4 items in any order -->
<userName>username</userName>
<password>password</password>
<agentCode>agentcode</agentCode>
<lang>en</lang>
</securityInfo>
</fram:getCountries>
</soapenv:Body>
</soapenv:Envelope>'; // data from the form, e.g. some ID number
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache"
"SOAPAction: http://testapi.roombookpro.com/en/soap/index#getCountries",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$url = $soapUrl;
// PHP cURL for https connection with auth
$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_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, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response2);
var_dump($parser);
echo $parser;
// user $parser to get your data out of XML response and to display it.
?>
In your code,your request is pointing to wsdl link below,
http://testapi.roombookpro.com/en/soap/index?wsdl
and thats why you are not getting soap response rather you getting the definitions.
you should use the following soap url to get the soap response,
http://testapi.roombookpro.com/en/soap/index
EDIT:
and to get the XML response (as string):
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
to get as SimpleXMLElement Object :
$xml = simplexml_load_string($response);
foreach ($xml->xpath('//ns2:Soap_Model_SOAP_Location_Country') as $item)
{
print_r($item);
//to access individual elements
// echo $item->id ;
// echo $item ->code;
// echo $item->name;
// echo "\n";
}
which gives array of XML objects:
SimpleXMLElement Object
(
[id] => 252
[code] => ZW
[name] => Zimbabwe
)
I have a simple form which i want to convert into a PHP backend system.
Now this form has an action to submit to a URL - the URL only accepts an invite only when a data with the name postdata and correct information is submitted (xml which has been encoded).
Works: - Note that the input name is called postdata and the value contains the xml which has been urlencoded and it works perfectly.
<form name="nonjava" method="post" action="https://url.com">
<input name="postdata" id="nonjavapostdata" type="hidden" value="<?xml version="1.0" encoding="utf-8"" />
<button type="submit" name="submit">Button</button>
</form>
However, i want to achieve the following by moving the postdata element within PHP as a lot of information is passed through that way.
Please note: the link is https but it wasnt working on local so i had to disable it within the CURL.
<?php
$url = 'https://super.com';
$xmlData = '<?xml version="1.0" encoding="utf-8"?>
<postdata
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<api>2</api>
</postdata>';
$testing = urlencode($xmlData);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "postdata=" . $testing);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$response = curl_exec($ch);
// Then, after your curl_exec call:
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
echo $header_size . '<br>';
echo htmlspecialchars($header) . '<br>';
echo htmlspecialchars($body) . '<br><br>';
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "$http_status for $url <br>";
?>
I keep getting a 302 error (which is the url content is not finding the data so its redirecting to a not found page.)
302 is NOT error; it just means you need to go to the redirected URL. A browser does that automatically for you. In PHP code, you would have to do it yourself. Look at the Location header on 302.
I tried to look if there is a way that Curl could be told to follow through redirects; many language HTTP libraries support that. This thread seems to suggest that CuRL also supports it - Is there a way to follow redirects with command line cURL
Your code works as it is supposed to, I am getting POST data:
Array ( [postdata] => <?xml version="1.0" encoding="utf-8"?> <postdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/20
01/XMLSchema"> <api>2</api> </postdata> )
as a result. The problem is on the receiving side, it isnt handling it correctly.
You need to follow the 302 redirect in curl. This is relatively easy to do by adding the location flag. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
This is the equivalent of doing curl -L at the CLI. You can see an example here in the php documentation.
I am passing an xml string to https://insurance-api.pingtree.co.uk/api through curl but is getting parameter error in response (code 12 0) which can be also seen if you browse the above mentioned url.The parameter is defined in the xml i.e. the campaign code then why isn't the system recognizing it. here is my code below which i also got from the http://www.quinternet.com site.
<?php
/**
* Initialize the request xml string here.
* The string in the tag like '[int]' should be replaced with actual value.
* The string in the square brackets is the data type.
*/
$request_string =
'<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:pt_service">
<soapenv:Header />
<soapenv:Body>
<urn:submit
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<campaign_code>dllfYg0JBwQ</campaign_code>
<site_url>www.surelifecover.co.uk</site_url>
<client_ip>127.0.0.1</client_ip>
<policy_type>J</policy_type>
<cover_purpose>1</cover_purpose>
<cover_amount>50000</cover_amount>
<cover_term>1</cover_term>
<title>1</title>
<first_name>INTRODUCERTEST</first_name>
<last_name>wwww</last_name>
<dob >1995-04-05</dob >
<email>will#bitscube.com</email>
<home_phone>07111111111</home_phone>
<best_call_time>1</best_call_time>
<gender>F</gender>
<is_smoker>Y</is_smoker>
<title2>1</title2>
<first_name2>ww</first_name2>
<last_name2>wwww</last_name2>
<dob2>1991-02-03</dob2>
<email2>913661383#qq.com</email2>
<home_phone2>07111111112</home_phone2>
<best_call_time2>2</best_call_time2>
<gender2>M</gender2>
<is_smoker2>N</is_smoker2>
<terms_consent>Y</terms_consent>
<privacy_content>Y</privacy_consent>
<mode>LIVE</mode>
<keyword>life ins</keyword>
<match_type>1</match_type>
<network>ABC</network>
<device>mobile</device>
<ref>00</ref>
<v1>var1</v1>
<v2>var2</v2>
<v3>var3</v3>
<v4>var4</v4>
<v5>var5</v5>
<i1>1</i1>
<i2>2</i2>
<i3>3</i3>
<i4>4</i4>
<i5>5</i5>
</urn:submit>
</soapenv:Body>
</soapenv:Envelope>
</env:Envelope>';
echo htmlspecialchars($request_string);
echo '<br>';
/**
* The values of the following fields please refer
*to the reference field list spec*
//setup the request headers here, notice at the action string and SOAPAction string */
$request_headers = array('Content-Type: application/soap+xml;charset=utf-8;action="urn:pt_service#Webservice#submit"',
'SOAPAction: "urn:pt_service#Webservice#submit"',
'Content-length: '.strlen($request_string) );
//setup the service url here
$service_url = 'https://insurance-api.pingtree.co.uk/api';
//setup the user agent for the request
$user_agent = $_SERVER['HTTP_USER_AGENT'];
//initialize the curl here
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLINFO_HEADER_OUT, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST,TRUE );
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_POSTFIELDS,$request_string);
curl_setopt($ch, CURLOPT_HTTPHEADER,$request_headers);
//do the submit process here
$result= curl_exec ($ch);
$response_string = curl_exec($ch);
// Convert API feed to xml object
var_dump($response_string);
$xml = simplexml_load_string($response_string);
$name = $xml->response->status;
echo $name;
//-----------------------------------------------
//parsing the response string here
/*example response below. Please get detail
refer for the reponse in specs.
<?xml version="1.0" encoding="UTF8"?>
<response>
<result>20</result>
<status>1</status>
<commission>10.00</commission>
<reference>347</reference>
<message><![CDATA[Accepted]]></message>
<redirect_url>
http://insurance-api.pingtree.co.uk/redirect?p=bUzbir4VhB-BB-Z_gMxVSy8YT15gxUB9iJMBGxi_aOq5PQuDBf_JPqgvc2egv6orCj6TJkeR5g6tX1y0D7hZgbV6DdBAlzbccKmkFNG4-PgWmaNR9LQ57cUQg6jTOXuB
</redirect_url>
</response>
//-----------------------------------------------*/
curl_close($ch);
?>
Situation: I am having to submit SOAP data to a remote server. The first request is for a URL that is needed for the second request. The URL returned starts the second request and is supposed to give me a return response of a bunch of user data in XML format.
Problem: I am getting an error back from the server on the second request (the data) that is referring to a C# problem and I do not know how to get around this. The error that I am trying to troubleshoot is:
The conversion could not be completed because the supplied DateTime
did not have the Kind property set correctly
HERE IS MY CODING
PHP:
error_reporting(E_ALL);
$soapUrl = "https://domain.com/insidews/insidews.asmx";
$soapUser = "*******";
$soapPassword = "***************************";
// xml post structure
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<inCredentials xmlns="http://inlogin.com/inSideWS">
<busNo>****************</busNo>
<password>******************</password>
</inCredentials>
</soap:Header>
<soap:Body>
<GetURL xmlns="http://inlogin.com/inSideWS" />
</soap:Body>
</soap:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"SOAPAction: http://inlogin.com/inSideWS/GetURL",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$url = $soapUrl;
$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_USERPWD, $soapUser.":".$soapPassword);
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); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
if(curl_errno($ch)){
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
//echo $response;
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
$parser = new SimpleXmlElement($response2);
foreach($parser as $p) {
foreach($p as $n) {
$new_url = $n;
}
}
$timezone = new DateTimeZone('UTC');
$dateone = '12/1/2013 00:00:00';
$startdate = new DateTime($dateone,$timezone);
$startdate = $startdate->format('c');
echo "Start Date: ".$startdate."<br><br>";
$datetwo = '12/31/2013 23:59:59';
$enddate = new DateTime($datetwo,$timezone);
$enddate = $enddate->format('c');
echo "End Date: ".$enddate."<br><br>";
echo "<font style='font-size: 18px; font-weight: bold; text-decoration: underline;'>FILE GET Destination URL:</font> ".$new_url."<br><br>";
$xml_post_string_2 = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<inCredentials xmlns="http://inlogin.com/inSideWS">
<busNo>**************</busNo>
<password>*******************************</password>
<timeZoneName>UTC</timeZoneName>
</inCredentials>
</soap:Header>
<soap:Body>
<DataDownloadReport_Run xmlns="http://inlogin.com/inSideWS">
<reportNo>16</reportNo>
<startDate>'.$startdate.'</startDate>
<endDate>'.$enddate.'</endDate>
</DataDownloadReport_Run>
</soap:Body>
</soap:Envelope>';
$new_headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"SOAPAction: http://inlogin.com/inSideWS/DataDownloadReport_Run",
"Content-length: ".strlen($xml_post_string_2),
);
// PHP cURL for https connection with auth
$cho = curl_init();
curl_setopt($cho, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($cho, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($cho, CURLOPT_URL, $new_url);
curl_setopt($cho, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($cho, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cho, CURLOPT_USERPWD, $soapUser.":".$soapPassword);
curl_setopt($cho, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($cho, CURLOPT_TIMEOUT, 10);
curl_setopt($cho, CURLOPT_POST, true);
curl_setopt($cho, CURLOPT_POSTFIELDS, $xml_post_string_2); // the SOAP request
curl_setopt($cho, CURLOPT_HTTPHEADER, $new_headers);
// converting
$second_response = curl_exec($cho);
// var_dump($second_response);
// var_dump(curl_getinfo($cho));
// var_dump(curl_error($cho));
if(curl_errno($cho)){
echo '<br><br>Curl error: ' . curl_error($cho);
}
//echo $second_response;
print_r($second_response);
curl_close($cho);
// converting
$new_response1 = str_replace("<soap:Body>","",$second_response);
$new_response2 = str_replace("</soap:Body>","",$new_response1);
// convertingc to XML
$new_parser = simplexml_load_string($second_response);
OUTPUT:
Start Date: 2013-12-01T00:00:00+00:00
End Date: 2013-12-31T23:59:59+00:00
FILE GET Destination URL: https://domain.com/inSideWS/inSideWS.asmx
string(0) "" soap:ServerSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentException: The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local. Parameter name: sourceTimeZone at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags) at System.TimeZoneInfo.ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo destinationTimeZone) at UCN.Common.TimeZoneUtilities.ConvertUTCToTimeZone(DateTime time, String id) in d:\Agents\7\inContact\RC-Web.inSideWS\Sources\C#\Library\Common\Utilities\TimeZoneUtilities.cs:line 109 at inContact.DataDownload.Report.GetData(String dataSourceModule, Int32 reportType) in d:\Agents\7\inContact\RC-Web.inSideWS\Sources\C#\Library\inContact.DataDownload\Report.cs:line 128 at inContact.DataDownload.Report.RunReport(Nullable`1 busNo, Nullable`1 reportNo, Nullable`1 maximumRows, Nullable`1 startIndex, String orderColumn, Nullable`1 orderASC, String searchText, Nullable`1& rowCount) in d:\Agents\7\inContact\RC-Web.inSideWS\Sources\C#\Library\inContact.DataDownload\Report.cs:line 78 at inSideWebService.inSideWS.DataDownloadReport_Run(Int32 reportNo, DateTime startDate, DateTime endDate) --- End of inner exception stack trace ---
I have fixed the issue. Translating the DateTime from PHP to C# should have worked but for some reason C# was not accepting the ISO8601 format like it was supposed to (as I was told it did). So I simply changed the following coding for the date:
$timezone = new DateTimeZone('UTC');
$time = time("00:00:00");
$dateone = '12/1/2013 00:00:00';
$startdate = date("Y-m-d", strtotime($dateone)) . 'T' . date("H:i:s", strtotime($dateone));
$datetwo = '12/31/2013 23:59:59';
$enddate = date("Y-m-d", strtotime($datetwo)) . 'T' . date("H:i:s", strtotime($datetwo));
This fixed the problem and I am now getting a response from the server.
Have you tried making the call using PHPs soap library, it takes care of most of the headers and intricacies associated with SOAP. The documentation is here http://www.php.net/manual/en/book.soap.php.
Someone just dumped a perl script on me and now it's my problem. I know nothing about Perl. Here's the script.
#! /usr/bin/perl
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
my $req = POST 'http://www.someurl.com/aff/', [ search => 'www', errors => 0 ];
my $xml = "<?xml version='1.0' encoding='UTF-8' ?>
<data xmlns='https://www.aff.gov/affSchema' sysID='Adin'
rptTime='2010-06-07T14:10:30.758-07:00' version='2.23'>
<msgRequest to='Co' from='trt' msgType='Data Request' subject='Async'
dateTime='2010-06-07T14:10:30.758-07:00'>
<body>2010-06-07T14:50:06Z</body>
</msgRequest>
</data>";
$req->content( $xml );
my $username = "providedUserName";
my $password = "providedPW";
$req->authorization_basic($username, $password);
print $ua->request($req)->as_string;
As far as I can tell it's creating a HTTP Request object, adding some content and printing the response. Google tells me that I need to install a Perl package to get a HTTPRequest object in PHP, which isn't an option. Is there anyway to do this with cURL or file_get_contents or something?
I'll keep tinkering away, but if anyone knows for sure how to do it, then it'll save me wasting my time at the very least.
This is an HTTP POST request with content type 'text/xml'. I believe you can do this with cURL as follows (example adapted from http://www.infernodevelopment.com/curl-php-send-post-data-background and is untested):
$x = curl_init("http://www.someurl.com/aff/");
curl_setopt($x, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($x, CURLOPT_HEADER, 0);
curl_setopt($x, CURLOPT_POST, 1);
curl_setopt($x, CURLOPT_RETURNTRANSFER, 1);
$xml = "<?xml version='1.0' encoding='UTF-8' ?>
<data xmlns='https://www.aff.gov/affSchema' sysID='Adin'
rptTime='2010-06-07T14:10:30.758-07:00' version='2.23'>
<msgRequest to='Co' from='trt' msgType='Data Request' subject='Async'
dateTime='2010-06-07T14:10:30.758-07:00'>
<body>2010-06-07T14:50:06Z</body>
</msgRequest>
</data>";
curl_setopt($x, CURLOPT_POSTFIELDS, $xml);
$username = "providedUserName";
$password = "providedPW";
curl_setopt($x, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($x, CURLOPT_USERPWD, "$username:$password");
$data = curl_exec($x);