如果使用的是httpClient:

                try {
HttpResponse response = HttpUtil.httpClient.execute(new HttpGet(url));
Header header = response.getFirstHeader("Set-Cookie");
if (header != null) {
String cookies = header.getValue();
String[] strings = cookies.split(";");
GlobalData.aspSessionScsbaabr = strings[0];
System.out.println("已经取到session = " + GlobalData.aspSessionScsbaabr);
}
} catch (IOException e) {
e.printStackTrace();
}

如果使用HttpUrlConnection:

try {
System.out.println("正在发送");
URL url = new URL(doLoginUrl);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);
InputStream inputStream = urlConnection.getInputStream();
String session_value = urlConnection.getHeaderField("Set-Cookie");
sessionId = session_value.split(";")[0];
System.out.println("sessionId = " + sessionId);
byte[] byte_result = new byte[inputStream.available()];
inputStream.read(byte_result);
String result = new String(byte_result); System.out.println("返回结果 result = " + result);
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}

Android 获取JSP或ASP的sessionId(Cookie)的更多相关文章

  1. JSP 状态管理 -- Session 和 Cookie

    Http 协议的无状态性 无状态是指,当浏览器发送请求给服务器的时候,服务器响应客户端请求.但是同一个浏览器再次发送请求给服务器的时候,服务器并不知道它就是刚才那个浏览器 session sessio ...

  2. 【转载】Asp.Net中Cookie对象的作用以及常见属性

    Cookie对象是服务器为用户访问存储的特定信息,这些信息一般存储在浏览器中,服务器可以从提交的数据中获取到相应的Cookie信息,Cookie的最大用途在于服务器对用户身份的确认,即票据认证,用户会 ...

  3. .NET跨平台之旅:ASP.NET Core从传统ASP.NET的Cookie中读取用户登录信息

    在解决了asp.net core中访问memcached缓存的问题后,我们开始大踏步地向.net core进军——将更多站点向asp.net core迁移,在迁移涉及获取用户登录信息的站点时,我们遇到 ...

  4. Asp.net操作cookie大全

    实例代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3 ...

  5. asp.net各种cookie代码和解析

    Cookie是一段文本信息,在客户端存储 Cookie 是 ASP.NET 的会话状态将请求与会话关联的方法之一.Cookie 也可以直接用于在请求之间保持数据,但数据随后将存储在客户端并随每个请求一 ...

  6. ASP.NET 操作Cookie详解 增加,修改,删除

    ASP.NET 操作Cookie详解 增加,修改,删除 Cookie,有时也用其复数形式Cookies,指某些网站为了辨别用户身份而储存在用户本地终端上的数据(通常经过加密).定义于RFC2109.它 ...

  7. .NET获取不到js写的cookie解决方法

    今晚使用javascript设置一个来路的cookie,之后使用ASP.NET获取这个cookie值,发现ASP.NET获取不到JS设置的cookie值,真郁闷中,以下是JS写Cookie的代码: C ...

  8. Android获取内置sdcard跟外置sdcard路径

    Android获取内置sdcard跟外置sdcard路径.(测试过两个手机,亲测可用) 1.先得到外置sdcard路径,这个接口是系统提供的标准接口. 2.得到上一级文件夹目录 3.得到该目录的所有文 ...

  9. Android获取系统时间方法的总结

    Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...

随机推荐

  1. Stored Procedures with Multiple Result Sets

    Stored Procedures with Multiple Result Sets https://msdn.microsoft.com/en-us/data/jj691402.aspx

  2. OpenGL7-3快速绘制(索引方式)

    代码下载#include "CELLWinApp.hpp"#include <gl/GLU.h>#include <assert.h>#include &l ...

  3. js笔记——浏览器及版本判断

    判断IE浏览器的时候注意需要做两个判断 一个是msie 一个是Edge function myBrowser(){ var userAgent = navigator.userAgent; //取得浏 ...

  4. Node.js 【Stream之笔记】

    从Node.js API文档中可知, 'A stream is an abstract interface implemented by various objects in Node. For ex ...

  5. Demo学习: CustomException

    CustomException 捕获程序发生的异常. 1. 抛出各种异常 procedure TMainForm.UniButton1Click(Sender: TObject); begin PBy ...

  6. iphone开发第一个UI应用程序QQ

    #import <UIKit/UIKit.h> @interface HViewController : UIViewController @property (retain, nonat ...

  7. Spark Streaming揭秘 Day16 数据清理机制

    Spark Streaming揭秘 Day16 数据清理机制 今天主要来讲下Spark的数据清理机制,我们都知道,Spark是运行在jvm上的,虽然jvm本身就有对象的自动回收工作,但是,如果自己不进 ...

  8. Nodejs & Mongod

    http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/

  9. Determining IP information for eth0… failed; no link present. Check cable

    [root@hexuweb101 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0添加下面代码: check_link_down () { return ...

  10. DevExpress GridControl 导出为Excel

    private void btnExport_ItemClick(object sender, EventArgs e)         {             SaveFileDialog sa ...