I am doing the online hotel booking using xml api(php) project.When i am working in the reservation code it shows error of the following
"Warning: file_get_contents(https://...@gmail.com</email><firstName>test</firstName><lastName>smith</lastName><homePhone>8870606867</homePhone><creditCardType>CA</creditCardType><creditCardNumber>5401999999999999</creditCardNumber>....</HotelRoomReservationRequest>) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 411 Length Required"
its my code
$context = stream_context_create(
array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded",
"Accept: application/xml"
)
)
);
$url ='https://book.api.ean.com/....';
$xml = file_get_contents($url, false, $context);
It's for sending credit information plz kindly give me suggestion what type of error... .
As per RFC2616 10.4.12:
You need to add the
Content-Length
header to yourPOST
request. That's the size in bytes (octets) of your POST request body. To obtain the length you could usestrlen
on the POST body. As your code example does not show any POST body, it's hard to give a concrete example. The post body is passed with the['http']['content']
entry in the stream context.Probably it's already enough if you set the
content
entry (see HTTP context optionsDocs).Edit: The following example code might solve your issue. It demonstrates how to send some XML to a server via a POST request using
file_get_contents
and setting headers including theContent-Length
header.If you need better error control, see the
ignore_errors
HTTP context optionDocs and$http_response_header
Docs. Detailed handling of HTTP response headers is available in a blog post of mine: HEAD first with PHP Streams.