小编siq*_*que的帖子

如何使用CookieStore在HttpUrlConnection中获取cookie?

在我的Application班上,我做了以下几点:

public class MyApplication extends Application {
    private static HttpURLConnection conn = null;
    public static CookieStore cookieStore;
    public static HttpContext localContext;
    public static DefaultHttpClient client = new DefaultHttpClient();

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        CookieSyncManager.createInstance(this);
        cookieStore = new BasicCookieStore();
        localContext = new BasicHttpContext();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

我有Runnable部分连接:

HttpURLConnection conn = null;
URL url;
try {
    url = new URL(requestUrl);
    conn = (HttpURLConnection) url.openConnection();                
    if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.FROYO) {
        System.setProperty("http.keepAlive", …
Run Code Online (Sandbox Code Playgroud)

cookies android httpurlconnection cookiestore

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

cookies ×1

cookiestore ×1

httpurlconnection ×1