首页 / 浏览问题 / 移动GIS / 问题详情
Android怎么通过post查询服务
81EXP 2019年08月30日

这是iserver发布的服务,现在想android通过传递参数,调用这个服务,获得空间查询的结果

json构造如下:

 String url = "http://192.168.5.229:8090/iserver/services/spatialAnalysis-b12m/restjsr/spatialanalyst/datasets/b12_1@barea/spatialquery3d";
String analysisType = "INTERSECTS";// 默认查询:相交

 try {
     JSONObject jsonObject = new JSONObject();
     jsonObject.put("type", "REGION");
     JSONArray jsonArray = new JSONArray();
     for (int i = 0; i < point2DList.size(); i++) {
         JSONObject jsonObject1 = new JSONObject();
         jsonObject1.put("x", point2DList.get(i).x);
         jsonObject1.put("y", point2DList.get(i).y);
         jsonArray.put(jsonObject1);
     }
     jsonObject.put("points", jsonArray);
     JSONObject body = new JSONObject();
     body.put("operateRegion", jsonObject);
     body.put("positionMode", "INTERSECTS");
     body.put("bottomAltitude", bottomHeight);
     body.put("extendedHeight", limitHeight);
     JSONObject jsonObject1 = new JSONObject();
     jsonObject1.put("attributeFilter", "");
     body.put("sourceDatasetFilter", jsonObject1);
     String s = body.toString();

     URL httpurl = new URL(url);
     HttpURLConnection conn = (HttpURLConnection) httpurl.openConnection();
     conn.setConnectTimeout(10000);
     // 设置允许输出
     conn.setDoOutput(true);
     conn.setDoInput(true);
     conn.setRequestMethod("POST");
     // 设置contentType
     conn.setRequestProperty("Content-Type", "application/json");
     DataOutputStream os = new DataOutputStream( conn.getOutputStream());
     String content = String.valueOf(body);
     os.writeBytes(content);
     os.flush();
     os.close();
     if(conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
         InputStreamReader in = new InputStreamReader(conn.getInputStream());
         BufferedReader bf = new BufferedReader(in);
         String recieveData = null;
         String result = "";
         while ((recieveData = bf.readLine()) != null){
             result += recieveData + "\n";
         }
         in.close();
         conn.disconnect();
         Log.e("msg", "quertPointBySpatial: "+result );
     }
 } catch (JSONException e) {
     e.printStackTrace();
 } catch (MalformedURLException e) {
     e.printStackTrace();
 } catch (IOException e) {
     e.printStackTrace();
 }

生成的Json参数如下:

{"operateRegion":{"type":"REGION","points":[{"x":113.3266251200566,"y":23.053786914728764},{"x":113.32662474278182,"y":23.053786658277005},{"x":113.32326017606414,"y":23.053787106296316},{"x":113.32326088882584,"y":23.05667035536284},{"x":113.32326424321552,"y":23.056690454972706},{"x":113.32326928307815,"y":23.056703159765902},{"x":113.32327585887036,"y":23.05671324111563},{"x":113.32328104770251,"y":23.056718606800775},{"x":113.32645086016392,"y":23.05671714079193},{"x":113.32662957498975,"y":23.05671576680439},{"x":113.32663041890272,"y":23.05671064496878},{"x":113.32663144890442,"y":23.05669943703532},{"x":113.32663210967725,"y":23.05668526483132},{"x":113.32663214433171,"y":23.056662408774052},{"x":113.32663093695668,"y":23.053794559388145},{"x":113.32662937428739,"y":23.05379190235328},{"x":113.32662797847605,"y":23.05378995100488},{"x":113.32662663647704,"y":23.053788386585047},{"x":113.32662516163485,"y":23.05378694869199},{"x":113.3266251200566,"y":23.053786914728764}]},"positionMode":"INTERSECTS","bottomAltitude":93,"extendedHeight":35,"sourceDatasetFilter":{"attributeFilter":""}}

post提交上去之后,不能获得返回的结果,请问这是哪一方面出错?

1个回答

您好,iMobile for Android是没有提供接口直接发布请求的,需要使用Android开发发送请求的方式。如果您是想发送post请求,您可以在移动端发送post请求提交。post请求的地址和参数在iserver帮助文档都是有说明的,麻烦请参考一下帮助文档。
9,242EXP 2019年08月30日
...