工作需要post调用天地图的服务,传送过去一串xml数据,参考网上的资料用以下方法实现,但在调用时页面返回Error 500的信息,不知道是不是代码什么地方出错了,麻烦各位指正,谢谢。
header("Content-Type: text/html;charset=utf-8");
$URL='http://114.255.197.181/wfsgchina1024/wfs';
$data_string='<?xml version:"1.0" encoding="UTF-8"?><wfs:GetFeature maxFeatures="100" service="WFS" version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd"><wfs:Query typeName="iso19112:SI_Gazetteer" srsName="EPSG:4326"><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:And><ogc:PropertyIsLike wildCard="*" singleChar="." escape="!"><ogc:PropertyName>STANDARDNAME</ogc:PropertyName><ogc:Literal>北京 天安门</ogc:Literal></ogc:PropertyIsLike></ogc:And></ogc:Filter></wfs:Query></wfs:GetFeature>';
$ch = curl_init();
$header[] = "Content-type: text/xml";//定义content-type为xml
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$response = curl_exec($ch);
if(curl_errno($ch))
{
print curl_error($ch);
}
curl_close($ch);
echo $response;备注:使用另外一个模拟post的方法fsockopen也出现同样问题。
header("Content-Type: text/html;charset=utf-8");
$URL='http://114.255.197.181/wfsgchina1024/wfs';
$data_string='<?xml version:"1.0" encoding="UTF-8"?><wfs:GetFeature maxFeatures="100" service="WFS" version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd"><wfs:Query typeName="iso19112:SI_Gazetteer" srsName="EPSG:4326"><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:And><ogc:PropertyIsLike wildCard="*" singleChar="." escape="!"><ogc:PropertyName>STANDARDNAME</ogc:PropertyName><ogc:Literal>北京 天安门</ogc:Literal></ogc:PropertyIsLike></ogc:And></ogc:Filter></wfs:Query></wfs:GetFeature>';
$ch = curl_init();
$header[] = "Content-type: text/xml";//定义content-type为xml
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$response = curl_exec($ch);
if(curl_errno($ch))
{
print curl_error($ch);
}
curl_close($ch);
echo $response;备注:使用另外一个模拟post的方法fsockopen也出现同样问题。
你可以换一个站点试试吧,google地图,map吧什么的,这些比较大型点,程序稳定些
$data_string="<?xml version='1.0' encoding='UTF-8'?>\n";
$data_string.="<wfs:GetFeature maxFeatures=\"100\" service=\"WFS\" version=\"1.0.0\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd\">";
$data_string.="<wfs:Query typeName=\"iso19112:SI_Gazetteer\" srsName=\"EPSG:4326\"><ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\">";
$data_string.="<ogc:And><ogc:PropertyIsLike wildCard=\"*\" singleChar=\".\" escape=\"!\">";
$data_string.="<ogc:PropertyName>STANDARDNAME</ogc:PropertyName><ogc:Literal>北京 天安门</ogc:Literal>";
$data_string.="</ogc:PropertyIsLike></ogc:And></ogc:Filter></wfs:Query></wfs:GetFeature>";
也多谢其他各位热心人的帮忙。