C#环境下使用 Get 和Post 的方式访问WFS服务
软件开发环境:VS2010
地图服务器:GeoServer 2.3.1
using
System;using
System.Collections.Generic;using
System.Linq;using
System.Web;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Net;using
System.Text;
private void GetUrlData()
{ WebClient client =
new WebClient(); stringrUrl = "http://10.14.1.34:8080/geoserver/wfs?service=WFS&version=1.0.0&request=getFeature&typeName=Shanxi:Toll&PROPERTYNAME=NAME,the_geom&FILTER=<Filter><PropertyIsEqualTo><PropertyName>KIND</PropertyName><Literal>8400</Literal></PropertyIsEqualTo></Filter>"; //client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(client_DownloadDataCompleted); byte[] ss = client.DownloadData(newUri(rUrl)); stringresult = Encoding.UTF8.GetString(ss); } privatevoid PostUrlData() { //将字符串转换成字节数组, 注意Encoding.UTF8这样才能支持中文查询 byte[] postBy = Encoding.UTF8.GetBytes(this.WfsData()); //初始化WebClient WebClient webClient =
new WebClient(); //webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); webClient.Headers.Add("Content-Type",
"application/xml;charset=UTF-8");
webClient.Headers.Add("ContentLength", postBy.Length.ToString()); //上传数据,返回页面的字节数组 byte[] responseData = webClient.UploadData(rUrl,
"POST", postBy); // 将返回的将字节数组转换成字符串(HTML);
stringsrcString = Encoding.UTF8.GetString(responseData); } privatestring WfsData() { var xmlPara =
"<?xml version='1.0' encoding='UTF-8'?>" +
"<wfs:GetFeature service='WFS' version='1.0.0' " +
"<wfs:Query typeName='Shanxi:Toll' srsName='EPSG:4326'>" //属性查询 +
"<ogc:And><ogc:PropertyIsLike wildCard='*' singleChar='.' escape='!'>" +
"<ogc:PropertyName>NAME</ogc:PropertyName>" +
"<ogc:Literal>*收费站*</ogc:Literal>" +
"</ogc:PropertyIsLike></ogc:And></ogc:Filter>" //空间查询 //+ "<ogc:Filter>"
//+ "<ogc:Intersects>"
//+ "<ogc:PropertyName>the_geom</ogc:PropertyName>"
//+ " <gml:Point srsName='http://www.opengis.net/gml/srs/epsg.xml#4326'>" //+ "<gml:coordinates>111.08158415999999,38.98932696</gml:coordinates>" //+ "</gml:Point>" //+ "</ogc:Intersects>" //+ "</ogc:Filter>" //后部分节点 +
"</wfs:Query>" +"</wfs:GetFeature>"; returnxmlPara; }转载自:https://blog.csdn.net/boy20000/article/details/9094487