In ICs, can`t get cookie

╄→尐↘猪︶ㄣ 提交于 2019-12-13 05:57:36

问题


cookie return always null...

In android 2.x this works well, but 4.0.4 ICS not works

ConnectivityManager manager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
CookieManager cookie = CookieManager.getInstance();

            if(cookie.getCookie(mContext.getString(R.string.host_url))!=null){
                conn.setRequestProperty("Cookie", cookie.getCookie(mContext.getString(R.string.host_url)));
                Log.d("tag", "cookie get " +  cookie.getCookie(mContext.getString(R.string.host_url)));
            }

in this code cookie.getCookie() return always null...

*using this code in HttpUrlConnection


回答1:


Try adding a dot in front of the url. For example if it was "domain.com" change it to ".domain.com" But still it wont work for previous versions. So check for the version and do if else. All version before 4.0 works good for "domain.com"



来源:https://stackoverflow.com/questions/10811848/in-ics-cant-get-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!