最近,我开始Hotelbeds APITUDE PHP API如何从hotelbeds apitude PHP API的gzip编码内容
工作我想通过pecl_http
现在我面临的一些问题,让gzip编码发送请求并得到响应数据通过API。以下是端点和头information
我想用下面的代码 -
$xml_part = <<< EOD
<availabilityRQ xmlns="http://www.hotelbeds.com/schemas/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" dailyRate="true">
<stay checkIn="2016-09-15" checkOut="2016-09-16"/>
<occupancies>
<occupancy rooms="1" adults="2" children="0">
<paxes>
<pax type="AD"/>
<pax type="AD"/>
</paxes>
</occupancy>
</occupancies>
<hotels>
<hotel>1067</hotel>
<hotel>1070</hotel>
</hotels>
<keywords>
<keyword>34</keyword>
<keyword>38</keyword>
<keyword>100</keyword>
</keywords>
<boards included="true">
<board>RO</board>
<board>BB</board>
</boards>
<rooms included="TRUE">
<room>DBT.ST</room>
</rooms>
<accommodations>
<accommodation>HOTEL</accommodation>
<accommodation>HOSTEL</accommodation>
</accommodations>
<reviews>
<review type="TRIPADVISOR" maxRate="5" minReviewCount="3"/>
</reviews>
<filter minRate="100.000" maxRate="170.000"/>
<filter minCategory="3" maxCategory="5"/>
<filter paymentType="AT_HOTEL"/>
<filter maxRatesPerRoom="3"/>
<filter packaging="TRUE"/>
<filter hotelPackage="YES"/>
<filter maxRooms="2"/>
</availabilityRQ> EOD;
$endpoint = "https://api.test.hotelbeds.com/hotel-api/1.0/hotels";
$body = new http\Message\Body();
$body->append($xml_part);
$request = new http\Client\Request("POST",
$endpoint,
["Api-Key" => $hotel_beds_config['api_key'],
"X-Signature" => $signature,
"Content-Type" => "application/xml",
"Accept" => "application/xml",
"Accept-encoding" => "Gzip"
],
$body
);
try {
$client = new http\Client;
$client->enqueue($request)->send();
$response = $client->getResponse();
if ($response->getResponseCode() != 200) {
printf($response->getBody());
} else {
echo '<pre>';
printf(json_encode($response->getBody()));
echo gzencode(json_encode($response->getBody()));
echo '</pre>';
}
} catch (Exception $ex) {
printf("Error while sending request, reason: %s\n", $ex->getMessage());
}
我得到200响应代码做一个API请求时。我所面临的所有问题都是从响应主体中检索数据。在输出我看到类似下面的编码数据 -
{}℃
我怎样才能获得的gzip编码的数据作为请求内容主体?