1. 程式人生 > >Android使用Asynchronous Http Client完成登入儲存cookie的問題

Android使用Asynchronous Http Client完成登入儲存cookie的問題


Persistent Cookie Storage with PersistentCookieStore 

This library also includes a PersistentCookieStore which is an implementation of the Apache HttpClient CookieStore interface that automatically saves cookies to SharedPreferences storage on the Android device. 

This is extremely useful if you want to use cookies to manage authentication sessions, since the user will remain logged in even after closing and re-opening your app. 

First, create an instance of AsyncHttpClient: 

AsyncHttpClient myClient = new AsyncHttpClient(); 
Now set this client’s cookie store to be a new instance of PersistentCookieStore, constructed with an activity or application context (usually this will suffice): 
Java程式碼  收藏程式碼
  1. PersistentCookieStore myCookieStore = new PersistentCookieStore(this);  
  2. myClient.setCookieStore(myCookieStore);  

Any cookies received from servers will now be stored in the persistent cookie store. 

To add your own cookies to the store, simply construct a new cookie and call addCookie: 

Java程式碼  收藏程式碼
  1. BasicClientCookie newCookie = new BasicClientCookie("cookiesare""awesome");  
  2. newCookie.setVersion(1);  
  3. newCookie.setDomain("mydomain.com");  
  4. newCookie.setPath("/");  
  5. myCookieStore.addCookie(newCookie);  

See the PersistentCookieStore Javadoc for more information. 

相關推薦

Android使用Asynchronous Http Client完成登入儲存cookie的問題

Persistent Cookie Storage with PersistentCookieStore  This library also includes a PersistentCookieStore which is an implementation of the Apache HttpClie

Android AsyncHttpClient登入儲存cookie和讀寫cookie

AsyncHttpClient有個特性:(11)持久化cookie儲存,可以將cookie儲存到你的應用程式的SharedPreferences中AsyncHttpClient Cookie相關的官方的文件This library also includes a Persis

Python3 Post登入並且儲存cookie登入其他頁面

import urllib.request import sys import http.cookiejar import urllib.parse from bs4 import BeautifulSoup import codecs import re #登入頁面 url = "h

【轉載儲存】Java丨jsoup網路爬蟲登入得到cookie並帶上cookie訪問

優秀文章:https://blog.csdn.net/wisdom_maxl/article/details/65631825 jsoup使用cookie: Set<Cookie> cookie_set = LoadCSDN.load(); // WebClient

python webdriver 儲存COOKIE 並使用COOKIE 跳過登入

from selenium.webdriver.support import expected_conditions as EC from selenium import webdriver from selenium.webdriver.common.by import By from s

實現一週之內自動登入cookie和session還有localStorage的儲存機制

這三個應該是最讓程式設計師頭疼的了,我利用簡單的登入介面的username和password來說明一下吧. 1.cookie用來儲存使用者相關資料,儲存的位置在使用者本地: 首先是登入介面定義: <form action="server.php" method="po

request post 模擬登入 csdn 獲取儲存cookie

# -*- coding=utf-8 -*- import requests from lxml import etree headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) Apple

關於Android使用Xutils的WebView儲存Cookie登入

/** * Sync Cookie */ private void syncCookie(Context context, String url){ try{ Log.d("Nat: webView.syncCookie.url", url);

Android studio沒有org.apache.http.client.HttpClient;等包問題 解決方案

target ace mon studio clas 技術 upload rep img 以前用Eclipse做Android開發工具一直使用apache的http做網絡請求,最近換用了Android studio發現沒有辦法引用apache的包,下面是我引用的步驟

使用 TRESTClient 與 TRESTRequest 作為 HTTP Client(轉)

pos 復制代碼 目前 android 也會 () 然而 stc dns 使用 TRESTClient 與 TRESTRequest 作為 HTTP Client 轉自:http://www.cnblogs.com/dennieschang/p/6966403.ht

通過http.client解析url返回的數據時為什麽中文變成了unicode碼

eval 數據 pen class except port nts sun ring 今天在解析json數據的時候得到了一堆這樣的數據:{"errNum":0,"errMsg":"success","retData":[{"title":"\u6536\u5e9f\u54c

Python3 requests與http.cookiejar的使用(cookie的保存與加載)

style load 3.x python2 name cep 請求 ignore session 在學習Python之余,發現Python2與Python3 有很大的變化,之前使用urllib和cookielib來保存cookie,發現很繁瑣,於是改用requests。發

go http client, http server

only lock nan ret str net con iou main Go語言中的HTTP client, server非常簡單。具體如下。 HTTP Server package main import ( "fmt" "htm

Net::HTTP 一次添加 cookie, body 發送post請求

utf host abcd master weight bsp sql code spa use Net::HTTP::Request; use Net::HTTP::URL; use Net::HTTP::Transport; my $url = Net::H

用最簡單的方式實現基於libevent框架的http client客戶端

#include <event2/event_struct.h> #include <event2/event.h> #include <event2/bufferevent.h> #include <event2/http.h> #include

Apache Http Client 在Android SDK 23中被移除

Android SDK API level 升級到23以後(Android 6.0)去掉了對於Apache Http Client的支援,Google的建議是用HttpURLConnection(API level 9以上),Google解釋說這個API的效率更高,它可以通過壓縮和響應快取減少

Golang 使用http Client下載檔案

之前使用beego的http庫的時候,有的情況需要下載檔案。beego是能實現,但就是有點問題:不支援回撥,沒法顯示下載速度,這在日常開發中是不可忍受的。 看了下beego的實現主要是使用了io.copy函式,於是就深入的看了下實現原理,發現挺簡單的,於是就根據io.copy原理實現的一個

[實戰]http client 無限等待返回結果

一、業務問題 公司內部有一個爬蟲系統,定時抓取部分網站資料存入我們資料庫,進行後續約業務邏輯處理。業務反饋有時有些網址的資料沒有抓取. 二、相關背景 軟體系統:  採用httpclient 4.5.3 + webmagic實現,定時作務觸發後,從資料庫分頁取出需要處理的資料

python cookiejar儲存cookie資訊

cookie資訊是什麼? cookie, 某些網站為了辨別使用者身份, 只有登陸之後才能訪問某個頁面; 進行一個會話跟蹤, 將使用者的相關資訊包括使用者名稱等儲存到本地終端 from http import cookiejar from urllib.request import

解決啟動時報ClassNotFoundException: org.apache.http.client.HttpClient異常的問題

最近在研究阿里的分散式事務框架GTS,在執行sample-txc-simple時,拋以下異常: JM.Log:INFO Set diamond-client log path: C:\Users\chanson\logs\diamond-client Exception in thread "m