工作需要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也出现同样问题。

解决方案 »

  1.   

    测试了一下,这个结果是'天地图'站点返回给你的,要么是你那段请求的字符串他们觉得有问题,要么就是他们自己的程序有问题,这个你自己要去判断,不过觉得他们的接口程序有问题的可能性大些吧
    你可以换一个站点试试吧,google地图,map吧什么的,这些比较大型点,程序稳定些
      

  2.   

    那段xml和服务地址都是天地图的技术人员给我的。天地图网站也是通过服务端模拟post来从这个地址获取数据。不过他们的服务端是jsp的,不知道有没影响?
      

  3.   


    $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>";
      

  4.   

    请确定你的请求是post还是put,仔细看接口的文档吧!
      

  5.   

    多谢3楼,原来是xml开头部分的格式有误。直接copy过来看得不是很仔细。麻烦你了。
    也多谢其他各位热心人的帮忙。