我的Android程序和会话cookie出现问题.
该会话只是没有在两次调用之间举行,甚至认为我正在使用cookieStore.
Web服务器代码是用DJango编写的,但是当我将C程序与libcurl一起使用时,会话将保留下来.
public class JsON {... DefaulthttpClIEnt httpClIEnt; cookieStore cookieStore; httpContext httpContext; httpResponse response = null; httpPost httpPost = null; httpGet httpGet = null;public JsON(Context context) { f_context = context; updateSettings(); httpParams myParams = new BasichttpParams(); httpconnectionParams.setConnectionTimeout(myParams, 10000); httpconnectionParams.setSoTimeout(myParams, 10000); httpClIEnt = new DefaulthttpClIEnt(myParams); cookieStore = new BasiccookieStore(); httpContext = new BasichttpContext(); httpContext.setAttribute(ClIEntContext.cookie_STORE, cookieStore);}...public String JsONSendCmd(String methodname) { String getUrl = URL + "Json/" + methodname+'/'; httpGet = new httpGet(getUrl); try { response = httpClIEnt.execute(httpGet,httpContext); } catch (Exception e) { } ...}
解决方法:
尝试这个:
List<cookie> cookies = httpclIEnt.getcookieStore().getcookies();if (!cookies.isEmpty()){ cookieSyncManager.createInstance(ClIEntContext.getInstance()); cookieManager cookieManager = cookieManager.getInstance(); // sync all the cookies in the httpclIEnt with the webvIEw // by generating cookie string for (cookie cookie : cookies) { cookie sessionInfo = cookie; String cookieString = sessionInfo.getname() + "=" + sessionInfo.getValue() + "; domain=" + sessionInfo.getDomain(); cookieManager.setcookie(ClIEntContext.getResources().getString(R.string.domain), cookieString); cookieSyncManager.getInstance().sync(); }}
总结 以上是内存溢出为你收集整理的会话Cookie和Android全部内容,希望文章能够帮你解决会话Cookie和Android所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)