HttpGet 获取webservice 数据

try {
			HttpGet httpget=new HttpGet(WSURL);
			try {
				HttpResponse httpresponse = httpclient.execute(httpget);
				// 获取返回数据  
	            HttpEntity entity = httpresponse.getEntity();  
	            String body = EntityUtils.toString(entity);  
	            if(entity!=null){
	            	entity.consumeContent();
	            }
	            body = body.replaceAll("&lt;", "<");
	            body = body.replaceAll("&gt;", ">");
	           
	            body = body.substring(76);
	            body = body.replaceFirst("</string>", "");
	            if(body.indexOf("Table")>-1){
	            	try {
						ScadaSiteGroup siteGroup = parseXml2Object(body);
						prehibsService.savePrehibsDatas(siteGroup);//保存
					} catch (Exception e) {
						e.printStackTrace();
					}
	            }
			} catch (HttpException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}

 HttpPost 获取webservice 数据非常方便

解析xml 使用dom4j 更加灵活

你可能感兴趣的:(webservice)