LBMP就是位置服务基础业务管理平台,东软开发的,介绍在这里

    LBMP的请求要求是这样的:

     业务平台通过HTTP  POST方式发送地理信息请求到GIS。请求行格式为:
    POST SP host SP HTTP/1.1 CRLF。
    请求中必须包含实体头Content-length,请求的消息体是XML格式的请求消息,其长度由Content-length指定。

    LBMP每次升级后,都需要我们对其业务进行测试,所以以前写了个测试的小程序,从文件中读取XML内容,发送给LBMP服务,查看返回结果。

    我以前程序请求LBMP服务用的是java.net.HttpURLConnection,今天学习HttpClient所以用HttpClient重写了一下测试程序。

      public static void main(String[] args) {
            BufferedReader in = null;
            HttpClient client = new HttpClient();
            PostMethod method = null;
            method = new PostMethod("http://XXX.XXXX.XX.XX:9211/LbmpService");
            method.setQueryString("");
            try {
                String out = getXmlStr("D:\\xml\\reqlbmp.xml");// 得到请求的XML
                method.setRequestHeader("Connection", "close");
                String reStr = null;
                StringBuffer readsf = new StringBuffer();
                method.setRequestEntity(new StringRequestEntity(out, "text/xml", "GBK"));
                client.executeMethod(method);
                in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), "GBK"));
                String inputLine = null;
                while ((inputLine = in.readLine()) != null) {
                    readsf.append(inputLine).append("\n");
                }
                reStr = readsf.toString();
                in.close();
                System.out.println(reStr);
    
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                method.releaseConnection();
                client.getHttpConnectionManager().closeIdleConnections(0);
                method = null;
                client = null;
            }
        }



    以前的代码是:

    public static void main(String[] args) {
    
    		URL url = null;
    		PrintWriter writer = null;
    		BufferedReader in = null;
    		HttpURLConnection conn = null;
    		try {
    			String out = getXmlStr("D:\\xml\\reqlbmp.xml");
    			url = new URL("http://XX.XXX.XX.XXX:10081/LbmpService");
    			conn = (HttpURLConnection) url.openConnection();
    			conn.setDoInput(true);
    			conn.setDoOutput(true);
    			System.out.println(out);
    			writer = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "utf-8"));
    			writer.print(out);// strXml
    			writer.flush();
    			writer.close();
    			// read date from server
    			in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "GBK"));
    			String s, s2 = new String();
    			int i = 0;
    			while ((s = in.readLine()) != null) {
    				s2 += s + "\n";
    			}
    			String content = s2.toString();
    			System.out.println("返回内容: \n" + content);
    			
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	
    	}