HttpURLConnection conn = (HttpURLConnection) url.openConnection();             //set cookie. sCookie is my static cookie string       if(sCookie!=null && sCookie.length()>0){         conn.setRequestProperty("Cookie", sCookie);                }       // Send data       OutputStream os = conn.getOutputStream();       os.write(mData.getBytes());       os.flush();       os.close();       // Get the response!       int httpResponseCode = conn.getResponseCode();           if (httpResponseCode != HttpURLConnection.HTTP_OK){        throw new Exception("HTTP response code: "+httpResponseCode);       }       // Get the data and pass them to the XML parser       InputStream inputStream = conn.getInputStream();               Xml.parse(inputStream, Xml.Encoding.UTF_8, mSaxHandler);               inputStream.close();       //Get the cookie       String cookie = conn.getHeaderField("set-cookie");       if(cookie!=null && cookie.length()>0){         sCookie = cookie;              }       /*  many cookies handling:                String responseHeaderName = null;       for (int i=1; (responseHeaderName = conn.getHeaderFieldKey(i))!=null; i++) {         if (responseHeaderName.equals("Set-Cookie")) {                  String cookie = conn.getHeaderField(i);          }       }*/               conn.disconnect(); 


http://stackoverflow.com/questions/3152740/android-post-data-and-cookies


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android中自带的样式
  2. android常用控件
  3. Android(安卓)主题和drawable state各个
  4. Android(安卓)GPS 定位的实现
  5. Android--shape虚线
  6. Android软硬整合设计与框架揭秘: HAL&Fram
  7. android版本总结
  8. android下载资源
  9. Android界面风格
  10. [Android]Android系统原理与开发要点系列