我收到了关于代码的XML请求的文件响应的提前结束。
无法弄清楚错误在哪里。
$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 to post to
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 into a variable
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_PORT, $port); //Set the 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);
尝试在帖子字段中发送数据但是没有用。 响应:
<!DOCTYPE DefaultRS SYSTEM 'https://xml.rentalcars.com:443//tj.dtd'><DefaultRS>
<Error id="2">
<Message>Premature end of file.</Message>
</Error>
</DefaultRS>
任何帮助表示赞赏。 感谢
答案 0 :(得分:0)
您需要对xml数据进行url编码,然后才能将其用作查询参数。因此,网址分配变为:
$url = 'https://secure.rentalcars.com/service/ServiceRequest.do?
serverName=www.rentalcars.com&xml='.urlencode(utf8_decode(trim($xml)));
注意,为了便于阅读,我刚刚将其包装起来 - 显然应该在一行上。
答案 1 :(得分:0)
在尝试了很多变化后,我终于成功了。
有两件事情是有问题的。
utf8_decode应为utf8_encode
POSTFIELDS数据应该是一个数组
否则解析器将抛出文件的过早结束或不发回任何内容。