String requestUrl = RequestUrlMng.getHost(context)+"/mservices/user/updateNickname.action?nickname="+nickname;HttpGet httpRequest = new HttpGet(requestUrl);try{HttpClient httpClient = new DefaultHttpClient();HttpResponse httpResponse = httpClient.execute(httpRequest);if(httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK){     Log.e("XXX", "can't reach:"+httpResponse.getStatusLine().getStatusCode());     return;}SAXParserFactory factory = SAXParserFactory.newInstance();SAXParser parser = factory.newSAXParser();XMLContentHandler handler = new XMLContentHandler();parser.parse(httpResponse.getEntity().getContent(), handler);Toast.makeText(context, handler.getResult().getStatus()+":"+handler.getResult().getMsg(), Toast.LENGTH_LONG).show();}catch(Exception e){Log.e("XXX", e.getMessage());}

class XMLContentHandler extends DefaultHandler{private RequestResult res;private static final String STATUS = "status";private static final String MSG = "msg";private String tmpStr;private String content;public RequestResult getResult(){return res;}@Overridepublic void startDocument() throws SAXException{}@Overridepublic void characters(char[] ch,int start,int length)                    throws SAXException{     content = new String(ch,start,length);}@Overridepublic void startElement(String uri,String localName,String name,Attributes attrs) throws SAXException{if("result".equals(localName)){res = new RequestResult();Log.i("XXX", "");}tmpStr = localName;}@Overridepublic void endElement(String uri,String localName,String name)                          throws SAXException{if(STATUS.equals(localName))res.setStatus(content);else if(MSG.equals(localName))res.setMsg(content);if("result".equals(localName))Log.i("XXX", "");else    Log.i("XXX", "<"+localName+">"+content+"");}}

xml文件格式:

0成功



更多相关文章

  1. Android(安卓)和 JS 交互时调用不成功解决方法
  2. android 4.0 内核(3.0)编译方法
  3. Android(安卓)OKhttp 上传文件袋参数
  4. android群发短信时判断短信是否发送成功
  5. Android使用自带JSONObject解析JSON数据
  6. 2021年Android进阶者的新篇章,成功拿下大厂offer
  7. Android(安卓)重力感应选号码
  8. Android程序在genymotion模拟器上能够成功安装但无法运行,点击app
  9. Android移植成功:linux-2.6.25.8+U盘挂载

随机推荐

  1. Android的绘制详解(Canvas、Paint、Path
  2. LinearLayout中的layout_weight属性
  3. android 安卓APP获取手机设备信息和手机
  4. Fragment 与 ListView, BaseAdapter
  5. Android(安卓)TextView 文本折叠效果
  6. OPhone SDK
  7. android 之 PhoneGap+jQuery Mobile+Rest
  8. Bitmap recycle()
  9. Android(安卓)安卓动画 属性动画 - 组合
  10. 如何解决:Android中 Error generating fin