如何在PHP中使用这种SOAP Request XML进行请求?
http://115.248.39.80/biyahekoapi/domesticair.asmx
我正在使用CodeIgniter开发此类网站并预订航班。我曾尝试过SoapClient和CURL,但没有回复。
$url = $API_DETAILS['URL']."?WSDL";
$params = array('encoding' => 'UTF-8', 'soap_version' => SOAP_1_2, 'trace' => 1, 'login' => $API_DETAILS['USER'], 'password' => $API_DETAILS['PASS']);
$client = new SoapClient($url, $params);
$security_param = array(
"WebProviderLoginId" => $API_DETAILS['USER'],
"WebProviderPassword" => $API_DETAILS['PASS']
);
$item_param = array(
"Origin" => $B_ORIGIN,
"Destination" => $B_DESTINATION,
"TravelDate" => $DEP_DATE
);
$journey_param = array(
"Item" => $item_param
);
$request_param = array(
"BookingType" => $B_WAY,
"JryDetails" => $journey_param,
"ClassType" => "E",
"Airlinecodes" => "",
"No_of_Adults" => $B_ADULTS,
"No_of_Childs" => $B_CHILD,
"No_of_Infants" => $B_INFANT,
"SeniorCitizen" => $B_SENIOR,
"ResidentofPhilippines" => 1,
"TransFeeFlag" => $FEE_DETAILS['DOMESTIC']
);
$result_params = array(
"pobjSecurity" => $security_param,
"PstrInput" => array(
"AvailabilityRequest" => $request_param
),
"PstrFinalOutPut" => NULL,
"pstrError" => NULL
);
//print_r($result_params);
$result = $client->__soapCall("AirGetAvailability", array($result_params));
print_r($result);
当我运行此代码时,它给了我这个:
stdClass Object([AirGetAvailabilityResult] => [pstrError] => Data at the root level is invalid. Line 1, position 1.)
哪个部分出错?
这是我的CURL代码:
$soapAction = $API_DETAILS['URL'] . '?WSDL';
$soapUrl = $API_DETAILS['URL'];
$B_RETURN = '';
$DEP_DATE = date('m/d/Y', strtotime($B_DEPARTURE));
$xml_post_string = htmlentities('<AvailabilityRequest><BookingType>O</BookingType><JryDetails><Item><Origin>'.$B_ORIGIN.'</Origin><Destination>'.$B_DESTINATION.'</Destination><TravelDate>'.$DEP_DATE.'</TravelDate></Item></JryDetails><ClassType>E</ClassType><Airlinecodes></Airlinecodes><No_of_Adults>'.$B_ADULTS.'</No_of_Adults><No_of_Childs>'.$B_CHILD.'</No_of_Childs><No_of_Infants>'.$B_INFANT.'</No_of_Infants><SeniorCitizen>'.$B_SENIOR.'</SeniorCitizen><ResidentofPhilippines>1</ResidentofPhilippines><TransFeeFlag>'.$FEE_DETAILS['DOMESTIC'].'</TransFeeFlag></AvailabilityRequest>');
$text_string = '<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap12:Body><AirGetAvailability xmlns="http://www.biyaheko.com/biyahekoapi/domesticair/"><pobjSecurity><WebProviderLoginId>'.$API_DETAILS['USER'].'</WebProviderLoginId><WebProviderPassword>'.$API_DETAILS['PASS'].'</WebProviderPassword></pobjSecurity><PstrInput>'.$xml_post_string.'</PstrInput><PstrFinalOutPut /><pstrError /></AirGetAvailability><soap12:Body></soap12:Envelope>';
//echo $text_string;
$headers = array(
"POST /biyahekoapi/domesticair.asmx HTTP/1.1",
"Host: 115.248.39.80",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($text_string)
);
try{
$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
//curl_setopt($ch, CURLOPT_USERPWD, '"'.$API_DETAILS['USER'].':'.$API_DETAILS['PASS'].'"');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $text_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$response1 = str_replace("<soap12:Body>","",$response);
$response2 = str_replace("</soap12:Body>","",$response1);
$parser = simplexml_load_string($response2);
echo $parser;
}catch(exception $E){
echo 'Error: ' . $E.message();
}