php - Premature end of file. XML response -


i getting premature end of file response xml request following code.

cant figure out error.

    $xml = '<?xml version="1.0" ?>';     $xml .= '<pickupcitylistrq>';     $xml .= '<credentials username="'.$api->username.'" password="'.$api->password.'" remoteip="'.$api->remoteip.'" />';     $xml .= '<country>uk</country>';     $xml .= '</pickupcitylistrq>';      $url = 'https://secure.rentalcars.com/service/servicerequest.do?servername=www.rentalcars.com&xml='.utf8_decode(trim($xml));     $port = 443;      $user_agent = $_server['http_user_agent'];     $ch = curl_init();                              // initialize curl handle     curl_setopt($ch, curlopt_url, $url);            // set url post     curl_setopt($ch, curlopt_failonerror, true);    // fail on errors      if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'off'))         curl_setopt($ch, curlopt_followlocation, true);// allow redirects     curl_setopt($ch, curlopt_returntransfer, true);    // return variable     curl_setopt($ch, curlopt_httpauth, curlauth_any);     curl_setopt($ch, curlopt_port, $port);          //set port number     curl_setopt($ch, curlopt_timeout, 30);          // times out after 15s     //curl_setopt($ch, curlopt_post, true);     //curl_setopt($ch, curlopt_postfields, '&xml='.$xml);     // add post fields     curl_setopt($ch, curlopt_useragent, $user_agent);     if ($port==443) {         curl_setopt($ch, curlopt_ssl_verifyhost, 2);         curl_setopt($ch, curlopt_ssl_verifypeer, false);     }     curl_setopt($ch, curlopt_httpheader, array('content-type:application/xml; charset=utf-8', 'accept: application/xml; charset=utf-8'));     $data = curl_exec($ch);     curl_close($ch); 

have tried sending data in post fields did not work. response:

<!doctype defaultrs system 'https://xml.rentalcars.com:443//tj.dtd'><defaultrs> <error id="2"> <message>premature end of file.</message> </error> </defaultrs> 

any appreciated. thanks

you need url encode xml data before can use query parameter. url assignment becomes:

$url = 'https://secure.rentalcars.com/service/servicerequest.do?   servername=www.rentalcars.com&xml='.urlencode(utf8_decode(trim($xml))); 

note, i've wrapped readability - should on 1 line.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -