用post请求方式实现对地图服务的基本操作
ArcGIS Server REST API 中的很多操作都可以用以下方式实现,具体参数的设置请查看其中的详细说明
1 public List<string> getGeometry(string CZAH, string url) 2 { 3 url += "/query";//query url 4 string postString = "where=CZAH='" + CZAH + "'";//where 5 //postString += "text=04CH88131210000004"; 6 postString += "&" + "returnGeometry=true";//returnGeometry 7 postString += "&" + "f=json";//json 8 string result = getPostData(postString, url); 9 List<string> list = new List<string>(); 10 var result1 = JsonConvert.DeserializeObject<dynamic>(result);//添加Newtonsoft.Json类库并引用; 11 var list1 = result1.features as IEnumerable<dynamic>; 12 dynamic[] jsonfea = list1.ToArray(); 13 for (int i = 0; i < jsonfea.Length; i++) 14 { 15 list.Add(jsonfea[i].geometry.ToString()); 16 } 17 return list; 18 } 19 20 /// <summary> 21 /// 获取post后的返回值 22 /// </summary> 23 /// <param name="postString">POST String</param> 24 /// <param name="url">Post URL</param> 25 /// <returns></returns> 26 public string getPostData(string postString, string url) 27 { 28 string result = ""; 29 try 30 { 31 byte[] postData = Encoding.UTF8.GetBytes(postString); 32 WebClient webClient = new WebClient(); 33 string method = "POST"; 34 //POST Header 35 webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); 36 //webClient.Headers.Add("Cache-Control", "no-cache"); 37 //同步提交请求,并返回数据 38 byte[] responseData = webClient.UploadData(url, method, postData);//得到返回字符流 39 result = Encoding.UTF8.GetString(responseData);//解码 40 } 41 catch (Exception) 42 { 43 throw; 44 } 45 return result; 46 }
多看一行书,就少写一行代码,记录点滴,用心生活。