如何使用Postman和php发送soap 4.0标头

时间:2019-12-06 06:40:09

标签: php soap postman soapheader amadeus

我想使用Amadeus API进行搜索排期。 我购买了企业帐户。 他们向我提供了凭据。 但是也许我的要求没有达到目标。 我正在通过邮递员尝试。 但是,返回与在浏览器中打开时相同的响应。 即我的请求参数未找到网址:

enter image description here

这是我的代码


$soapUrl = "https://noded2.test.webservices.amadeus.com/".$wsap;
/*
$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><SearchCollectionPoint xmlns="http://privpakservices.schenker.nu/"><customerID>XXX</customerID><key>XXXXXX-XXXXXX</key><serviceID></serviceID><paramID>0</paramID><address>RiksvŠgen 5</address><postcode>59018</postcode><city>Mantorp</city><maxhits>10</maxhits></SearchCollectionPoint></soap12:Body></soap12:Envelope>';
*/
$xml_post_string  = '';
$xml_post_string .= '<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" xmlns:ses="http://xml.amadeus.com/2010/06/Session_v3">';
$xml_post_string .= '<soap:Header>';
// $xml_post_string .= '<add:MessageID xmlns:add="http://www.w3.org/2005/08/addressing">2fc42c4e-d34f-414e-b064-d37acd6bdc9c</add:MessageID>';
$xml_post_string .= '<add:MessageID xmlns:add="http://www.w3.org/2005/08/addressing">'.$MessageID.'</add:MessageID>';
$xml_post_string .= '<add:Action xmlns:add="http://www.w3.org/2005/08/addressing">http://webservices.amadeus.com/FMPTBQ_18_1_1A</add:Action>';
$xml_post_string .= '<add:To xmlns:add="http://www.w3.org/2005/08/addressing">https://noded2.test.webservices.amadeus.com/'.$wsap.'</add:To>';
$xml_post_string .= '<link:TransactionFlowLink xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1" />';
$xml_post_string .= '<oas:Security xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:oas1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">';
$xml_post_string .= '<oas:UsernameToken oas1:Id="UsernameToken-1">';
$xml_post_string .= '<oas:Username>'.$wbs_user_id.'</oas:Username>';
$xml_post_string .= '<oas:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">'.$nonce.'</oas:Nonce>';
$xml_post_string .= '<oas:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">'.$passworddigest.'</oas:Password>';
$xml_post_string .= '<oas1:Created>'.$created.'</oas1:Created>';
$xml_post_string .= '</oas:UsernameToken>';
$xml_post_string .= '</oas:Security>';
$xml_post_string .= '<AMA_SecurityHostedUser xmlns="http://xml.amadeus.com/2010/06/Security_v1">';
$xml_post_string .= '<UserID AgentDutyCode="SU" POS_Type="1" PseudoCityCode="'.$office_id.'" RequestorType="U" />';
$xml_post_string .= '</AMA_SecurityHostedUser>';
$xml_post_string .= '</soap:Header>';
$xml_post_string .= '<soap:Body>';
$xml_post_string .= '<Fare_MasterPricerTravelBoardSearch>';
$xml_post_string .= '<numberOfUnit>';
$xml_post_string .= '<unitNumberDetail>';
$xml_post_string .= '<numberOfUnits>30</numberOfUnits>';
$xml_post_string .= '<typeOfUnit>RC</typeOfUnit>';
$xml_post_string .= '</unitNumberDetail>';
$xml_post_string .= '<unitNumberDetail>';
$xml_post_string .= '<numberOfUnits>1</numberOfUnits>';
$xml_post_string .= '<typeOfUnit>PX</typeOfUnit>';
$xml_post_string .= '</unitNumberDetail>';
$xml_post_string .= '</numberOfUnit>';
$xml_post_string .= '<paxReference>';
$xml_post_string .= '<ptc>ADT</ptc>';
$xml_post_string .= '<traveller>';
$xml_post_string .= '<ref>1</ref>';
$xml_post_string .= '</traveller>';
$xml_post_string .= '</paxReference>';
$xml_post_string .= '<fareOptions>';
$xml_post_string .= '<pricingTickInfo>';
$xml_post_string .= '<pricingTicketing>';
$xml_post_string .= '<priceType>ET</priceType>';
$xml_post_string .= '<priceType>RP</priceType>';
$xml_post_string .= '<priceType>RU</priceType>';
$xml_post_string .= '</pricingTicketing>';
$xml_post_string .= '</pricingTickInfo>';
$xml_post_string .= '</fareOptions>';
$xml_post_string .= '<travelFlightInfo />';
$xml_post_string .= '<itinerary>';
$xml_post_string .= '<requestedSegmentRef>';
$xml_post_string .= '<segRef>1</segRef>';
$xml_post_string .= '</requestedSegmentRef>';
$xml_post_string .= '<departureLocalization>';
$xml_post_string .= '<departurePoint>';
$xml_post_string .= '<locationId>NYC</locationId>';
$xml_post_string .= '</departurePoint>';
$xml_post_string .= '</departureLocalization>';
$xml_post_string .= '<arrivalLocalization>';
$xml_post_string .= '<arrivalPointDetails>';
$xml_post_string .= '<locationId>MIA</locationId>';
$xml_post_string .= '</arrivalPointDetails>';
$xml_post_string .= '</arrivalLocalization>';
$xml_post_string .= '<timeDetails>';
$xml_post_string .= '<firstDateTimeDetail>';
$xml_post_string .= '<date>171219</date>';
$xml_post_string .= '</firstDateTimeDetail>';
$xml_post_string .= '</timeDetails>';
$xml_post_string .= '</itinerary>';
$xml_post_string .= '</Fare_MasterPricerTravelBoardSearch>';
$xml_post_string .= '</soap:Body>';
$xml_post_string .= '</soap:Envelope>';

header('Content-Type: text/xml');
// echo $xml_post_string;

$headers = array(
"POST ".$wsap." HTTP/1.1",
"Host: noded2.test.webservices.amadeus.com",
"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);

1 个答案:

答案 0 :(得分:0)

只需将<add:Action>元素中的值添加到“ SOAPAction”标头即可。 enter image description here