1

ビジネスアプリケーションをモバイルに移植するためのアプリを開発しています。Cookieについては、sharedPreferencesに保存し、アプリケーションの起動時にこれを確認し、Cookieがあれば取​​得し、 cookieStore に入れ、 cookieStore を httpContext に入れ_myContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);ます。このコンテキストは、httpClient.execute(request, myContext) のパラメーターとして送信されます。ここで、デバッグ モードで、context、cookie、cookieStore 応答 ecc、および ALL VALUES の値が正しいことを確認しましたが、ログインしていないため、サーバーから応答がありました。誰か助けてください。Cookie を管理するコードは次のとおりです。

プライベート静的 HttpContext handleCookieStore() {

try {

        if (_myContext == null ) {

            _myContext = new BasicHttpContext();
        }

        // Instantiate and fill cookieStore
        CookieStore cookieStore = (CookieStore)_myContext.getAttribute(ClientContext.COOKIE_STORE);

        if ( cookieStore == null ) {

            // Instantiate new coockieStore
            cookieStore = new BasicCookieStore();


            // Instantiate utility class
            Utility utility = new Utility(_sharedPref);

            Map<String, ?> sessionCookie = utility.getSessionCookie();

            // Look for existing cookies into sharing pref
            if( sessionCookie != null ) {

                // Instantiate a map of string for iterate on cookie's values saved in sharedPref
                Map<String, ?> cookies = sessionCookie;

                // Take all the keys
                Object [] keys = cookies.keySet().toArray();

                for (int i=0; i<cookies.size(); i++ ) { 

                    String name = (String) keys[i];
                    String value = (String) cookies.get(keys[i]);

                    Cookie cookie = new BasicClientCookie( name , value );

                    cookieStore.addCookie(cookie);
                }

                // Set store to context
                _myContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

            } else {
                //

                _myContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
            }

        } else {
            Utility utility = new Utility(_sharedPref);

            // Read the existing cookies
            List<Cookie> cookies = cookieStore.getCookies();

            for(Cookie cookie : cookies) {

                System.out.println("c = " + cookie.getName() + " : " + cookie.getValue());

                // Save cookie value into shared preferences
                utility.saveSessionCookie(cookie.getName(), cookie.getValue() );
            }

        }

} catch (Exception e) {

    Log.e("exception->CustomHttpClient.handleCookie", " " + e);
    return null;
}
// Return current context
return _myContext;

}

よろしくお願いします!

4

0 に答える 0