Search code examples
phpsoapcurlwsdlsoap-client

soapenv:Server.userExceptionorg.xml.sax.SAXParseException: Content is not allowed in prolog for Hotelbed WSDL api


I got response 500 internal server error when i run below code, I think code is perfect, so can anyone help me about this?

<?php
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$xml .= '<CountryListRQ echoToken="DummyEchoToken" xmlns="http://www.hotelbeds.com/schemas/2005/06/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hotelbeds.com/schemas/2005/06/messages CountryListRQ.xsd">';
$xml .= '<Language>ENG</Language>';
$xml .= '<Credentials>';
$xml .= '<User>username</User>';
$xml .= '<Password>password</Password>';
$xml .= '</Credentials>';
$xml .= '</CountryListRQ>';

$url = 'http://212.170.239.71/appservices/ws/FrontendService?wsdl';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml; charset=utf-8; action="getCountryList"'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('xml' => $xml));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$result = @curl_exec($ch);
echo "<pre>";
print_r($result);
exit;
if($result === false) {
    echo "Error performing request";
} else {
    $xml_doc = simplexml_load_string($result);
    echo 'status is ', $xml_doc->status, '<br/>';
    if ($xml_doc->status == 'SUCCESS') {
        print_r($result);
    } else {
        echo 'Error is ', $xml_doc->errormessage, '<br/>';
    }
}?>

I got response like this,

HTTP/1.1 100 Continue

HTTP/1.1 500 Internal Server Error
Date: Sat, 02 Feb 2013 06:02:12 GMT
Server: Resin/2.1.17
Content-Type: text/xml; charset=utf-8
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked

soapenv:Server.userExceptionorg.xml.sax.SAXParseException: Content is not allowed in prolog.we3mpf01

Can anyone help me? How can i get country list using this hotelbed api?


Solution

  • Use below http service url :

    http://212.170.239.71/appservices/http/AcceptanceTest
    

    I thing on the time hotelbeds server was down, that's why this error happen.