它说浏览器发送了一个服务器无法理解的请求。我不完全理解我的 PHP 代码出了什么问题。有人可以帮我理解我哪里出错了。谢谢 !
<?php
$url ="http://127.0.0.1/sensor/sens/data.php";
$xml_data = file_get_contents("/usr/local/www/data/data.xml");
$header ="POST HTTP/1.0 \r\n";
$header .="Content-type: text/xml \r\n";
$header .="Content-length: ".strlen($xml_data)." \r\n";
$header .="Content-transfer-encoding: text\r\n";
$header .="Connection: close \r\n\r\n";
$header .= $xml_data;
$ch = curl_init();
curl_setopt ($ch,CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$header);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
$data = curl_exec($ch); // if the post is successful , the server will return some data.
echo $data;
#$info = curl_getinfo($ch);
#
#if(!curl_errno($ch))
# echo 'It took '.$info['total_time'].'seconds to send a request to'.$info['url'];
#
# else
#
curl_close($ch);
echo $data;
?>