Open raselcse10 opened 6 years ago
Hi raselcse10,
Could you please confirm you are sending proper password in the code. In the code it is written as 'my password'. Thanks.
Hello vivekjyotipramanik,
Yes i am sending proper target branch no and password. Due to this public place i set this information to mypassword.
Hello vivekjyotipramanik,
Check your email.
Hi raselcse10,
I have not received the mail yet. Thanks.
check now
check now
Hi raselcse10,
I have received it. We will check this and will provide an update. Thanks.
ok i will wait for your response.
Hi raselcse10,
The taregtBranch in the first line of the xml request should be assigned as $TARGETBRANCH. I have changed that and now the code is working fine and sending back response. Please find below the updated code. Please let us know how it goes. Thanks.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$TARGETBRANCH = "targetBranch";
$CREDENTIALS = "Universal API/uAPI1711256462-9d2cbace:password";
$Provider = "1G";
$message = <<<EOM
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<LowFareSearchReq xmlns="http://www.travelport.com/schema/air_v42_0" TraceId="trace" TargetBranch="$TARGETBRANCH" ReturnUpsellFare="true">
<BillingPointOfSaleInfo xmlns="http://www.travelport.com/schema/common_v42_0" OriginApplication="uAPI" />
<SearchAirLeg>
<SearchOrigin>
<CityOrAirport xmlns="http://www.travelport.com/schema/common_v42_0" Code="DAC" PreferCity="true" />
</SearchOrigin>
<SearchDestination>
<CityOrAirport xmlns="http://www.travelport.com/schema/common_v42_0" Code="HKG" PreferCity="true" />
</SearchDestination>
<SearchDepTime PreferredTime="2017-10-09" />
</SearchAirLeg>
<SearchAirLeg>
<SearchOrigin>
<CityOrAirport xmlns="http://www.travelport.com/schema/common_v42_0" Code="HKG" PreferCity="true" />
</SearchOrigin>
<SearchDestination>
<CityOrAirport xmlns="http://www.travelport.com/schema/common_v42_0" Code="DAC" PreferCity="true" />
</SearchDestination>
<SearchDepTime PreferredTime="2017-10-29" />
</SearchAirLeg>
<AirSearchModifiers>
<PreferredProviders>
<Provider xmlns="http://www.travelport.com/schema/common_v42_0" Code="1G" />
</PreferredProviders>
</AirSearchModifiers>
<SearchPassenger xmlns="http://www.travelport.com/schema/common_v42_0" Code="ADT" />
<SearchPassenger xmlns="http://www.travelport.com/schema/common_v42_0" Code="CNN" Age="8" DOB="2009-09-18" />
<SearchPassenger xmlns="http://www.travelport.com/schema/common_v42_0" Code="INF" Age="0" DOB="2017-09-18" />
<AirPricingModifiers>
<AccountCodes>
<AccountCode xmlns="http://www.travelport.com/schema/common_v42_0" Code="-" />
</AccountCodes>
</AirPricingModifiers>
</LowFareSearchReq>
</soapenv:Body>
</soapenv:Envelope>
EOM;
$file = "001-".$Provider."_AirAvailabilityReq.xml"; // file name to save the request xml for test only(if you want to save the request/response)
prettyPrint($message,$file);//call function to pretty print xml
$auth = base64_encode("$CREDENTIALS");
$soap_do = curl_init ("https://apac.universal-api.pp.travelport.com/B2BGateway/connect/uAPI/AirService");
$header = array(
"Content-Type: text/xml;charset=UTF-8",
"Accept: gzip,deflate",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"\"",
"Authorization: Basic $auth",
"Content-length: ".strlen($message),
);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 60);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $message);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true); // this will prevent the curl_exec to return result and will let us to capture output
$return = curl_exec($soap_do);
$file = "001-".$Provider."_AirAvailabilityRsp.xml"; // file name to save the response xml for test only(if you want to save the request/response)
$content = prettyPrint($return,$file);
parseOutput($content);
//Pretty print XML
function prettyPrint($result,$file){
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
$dom->loadXML($result);
$dom->formatOutput = true;
outputWriter($file,$dom->saveXML());
return $dom->saveXML();
}
//function to write output in a file
function outputWriter($file,$content){
file_put_contents($file, $content); // Write request/response and save them in the File
}
function parseOutput($content){ //parse the Search response to get values to use in detail request
$AirAvailabilitySearchRsp = $content; //use this if response is not saved anywhere else use above variable
$xml = simplexml_load_String("$AirAvailabilitySearchRsp", null, null, 'SOAP', true);
// $xml = simplexml_load_file($AirAvailabilitySearchRsp);
if($xml)
echo "Processing! Please wait!";
else{
trigger_error("Encoding Error!", E_USER_ERROR);
}
$Results = $xml->children('SOAP',true);
foreach($Results->children('SOAP',true) as $fault){
if(strcmp($fault->getName(),'Fault') == 0){
trigger_error("Error occurred request/response processing!", E_USER_ERROR);
}
}
$count = 0;
$fileName = "flights.txt";
if(file_exists($fileName)){
file_put_contents($fileName, "");
}
$searchResult = [];
foreach($Results->children('air',true) as $nodes){
foreach($nodes->children('air',true) as $hsr){
if(strcmp($hsr->getName(),'AirSegmentList') == 0){
foreach($hsr->children('air',true) as $hp){
if(strcmp($hp->getName(),'AirSegment') == 0){
$count = $count + 1;
file_put_contents($fileName,"\r\n"."Air Segment ".$count."\r\n"."\r\n", FILE_APPEND);
foreach($hp->attributes() as $a => $b ){
$GLOBALS[$a] = "$b";
//echo "$a"." : "."$b";
$searchResult[$count][$a] = $b;
file_put_contents($fileName,$a." : ".$b."\r\n", FILE_APPEND);
}
}
}
}
//break;
}
}
/*
$Token = 'Token';
$TokenKey = 'TokenKey';
$fileName = "tokens.txt";
if(file_exists($fileName)){
file_put_contents($fileName, "");
}
foreach($Results->children('air',true) as $nodes){
foreach($nodes->children('air',true) as $hsr){
if(strcmp($hsr->getName(),'HostTokenList') == 0){
foreach($hsr->children('common_v42_0', true) as $ht){
if(strcmp($ht->getName(), 'HostToken') == 0){
$GLOBALS[$Token] = $ht[0];
foreach($ht->attributes() as $a => $b){
if(strcmp($a, 'Key') == 0){
file_put_contents($fileName,$TokenKey.":".$b."\r\n", FILE_APPEND);
}
}
file_put_contents($fileName,$Token.":".$ht[0]."\r\n", FILE_APPEND);
}
}
}
}
}
*/
echo "\r\n"."Processing Done. Please check results in files.";
echo "<pre>";
print_r($searchResult);
die();
}
?>
I am facing "DOMDocument::loadXML(): Empty string supplied" error in my development. In my server i can't see any error but when i run this same script from my development server i'm getting this error and can't proceed my development.
To review my code please go https://pastebin.com/6W8e3FZY and let me know why i'm getting below error.
Warning: DOMDocument::loadXML(): Empty string supplied as input in /var/www/html/dev.travel.com/success.php on line 89
Warning: simplexml_load_file(): I/O warning : failed to load external entity " " in /var/www/html/dev.travel.com/success.php on line 103
Fatal error: Encoding Error! in /var/www/html/dev.travel.com/success.php on line 108
Waiting for your quick response because of my beta version release date knocking my door.