我通过一个api发布一个请求进行现场预订。 当我通过一个表单操作发布数据并提交时,我将得到响应。 但是当我试图通过curl发布相同的url来获得响应时,我没有得到任何数据。
网址是: -
https://book.api.ean.com/ean-services/rs/hotel/v3/res?
minorRev=99
&cid=55505
&sig=1893d9f7e3e9fbd3f8a36f43cd61287d
&apiKey=1bn8n4or4tjajq23fe4l6m18lp
&customerUserAgent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
&customerIpAddress=223.30.152.118
&customerSessionId=e80df6de9008af772cfb48a389465415
&locale=en_US
¤cyCode=USD
&xml=<HotelRoomReservationRequest>
<hotelId>106347</hotelId>
<arrivalDate>10/30/2015</arrivalDate>
<departureDate>11/1/2015</departureDate>
<supplierType>E</supplierType>
<rateKey>469e1aff-49de-4944-a64d-25d96ccde3aa</rateKey>
<rateCode>200706716</rateCode>
<roomTypeCode>200127420</roomTypeCode>
<chargeableRate>252.00</chargeableRate>
<RoomGroup>
<Room>
<numberOfAdults>2</numberOfAdults>
<numberOfChildren>2</numberOfChildren>
<childAges>3,7</childAges>
<firstName>test</firstName>
<lastName>test</lastName>
<smokingPreference>NS</smokingPreference>
<bedTypeId>23</bedTypeId>
</Room>
</RoomGroup>
<ReservationInfo>
<email>test@travelnow.com</email>
<firstName>test</firstName>
<lastName>test</lastName>
<homePhone>2145370159</homePhone>
<workPhone>2145370159</workPhone>
<creditCardType>CA</creditCardType>
<creditCardNumber>5401999999999999</creditCardNumber>
<creditCardExpirationMonth>04</creditCardExpirationMonth>
<creditCardExpirationYear>2017</creditCardExpirationYear>
<creditCardIdentifier>123</creditCardIdentifier>
</ReservationInfo>
<AddressInfo>
<address1>travelnow</address1>
<city>Seattle</city>
<stateProvinceCode>WA</stateProvinceCode>
<countryCode>US</countryCode>
<postalCode>98117</postalCode>
</AddressInfo>
</HotelRoomReservationRequest>
我正在使用该代码
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
$header[] = "Accept: application/json";
$header[] = "Accept-Encoding: gzip";
$header[] = "Content-length: 0";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$verbose = fopen('php://temp', 'rw+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);
$result = curl_exec($ch);
echo '<pre>';
print_r($result);
请帮助我如何通过curl发布这些数据以获得响应。我在wordpress中使用它来进行付款预订。
答案 0 :(得分:1)
总结我发布的评论:
CURLOPT_POSTFIELDS
Content-length
,0值可以
是一个问题CURLOPT_HEADER
POST