Android 上的 HttpClient ??Cookie 存取策略

日期:2016/6/24 16:43:00 来源:本网整理 阅读:0
<无详细内??gt;

[1].[代码] [Java]代码 跳至 [1]

BasicHttpParams params = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.  
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_CONNECTION);
// Set the default socket timeout (SO_TIMEOUT) 
// in milliseconds which is the timeout for waiting for data.  
HttpConnectionParams.setSoTimeout(params, TIMEOUT_SOCKET);  

ConnManagerParams.setMaxTotalConnections(params, 5);
ConnManagerParams.setTimeout(params, TIMEOUT_TOTAL);

client = new DefaultHttpClient(params);

CookieStore cookieStore = new BasicCookieStore();
//Bind custom cookie store to the local context
client.setCookieStore(cookieStore);
CookieSpecFactory csf = new CookieSpecFactory() {			
public CookieSpec newInstance(HttpParams params) {
    return new BrowserCompatSpec() {
	@Override
	public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException 
	{
	    // Oh, I am easy
	    // allow all cookies
	    //log.debug("custom validate");
	}
    };
}
};
client.getCookieSpecs().register("oschina", csf);
client.getParams().setParameter(ClientPNames.COOKIE_POLICY, "oschina");
client.getParams().setParameter(CookieSpecPNames.SINGLE_COOKIE_HEADER, true);

  • 本文相关:
  • Android 实现自动接听和挂断电话功??/a>[代码]
    迷途d书童
  • 了解Android应用程序结构???小代码
  • 使用 Python 编写 Android ??UI 应用
  • Android 布局:头部、中间、尾??/a>[代码]
    walen
  • Android下Excel的操??/a>[代码]
    Elbiz
  • android 多媒体开发高级编??/a>[代码]
    liu447182356long
  • android页面特效大集??/a>[代码]
    蜗牛TT
  • 用Sqlite存储数据,实现增删改??/a>[代码]
    haoxuan
  • Android刷卡库(NDK??- mslib
  • android读取apk中已经存在的数据库信??/a>[代码]
    岳静
  • 免责声明 - 关于我们 - 联系我们 - 广告联系 - 友情链接 - 帮助中心 - 频道导航
    Copyright © 2015 www.zgxue.com All Rights Reserved