2013-07-24 1 views
5

私はこのようなGETリクエストを行います。LoopJ AndroidAsyncHttpと要求クッキー

final TextView text = (TextView) findViewById(R.id.textView); 
    AsyncHttpClient client = new AsyncHttpClient(); 
    client.get("http://example.com/mypage/", new AsyncHttpResponseHandler() { 
     @Override 
     public void onSuccess(String response) { 
      text.append(response); 
     } 
    }); 

私もクッキーを追加します。

PersistentCookieStore myCookieStore = new PersistentCookieStore(this); 
    client.setCookieStore(myCookieStore); 
    BasicClientCookie newCookie = new BasicClientCookie("id", 17882); 
    myCookieStore.addCookie(newCookie); 

しかし、私は送ることができますどのようにGETリクエストをしながらリクエストオブジェクトの中の私のクッキー? documentationクライアントにについて

は、これらのメソッドのシグネチャを持っています

void get(Context context, String url, AsyncHttpResponseHandler responseHandler) 
void get(Context context, String url, Header[] headers, RequestParams params, AsyncHttpResponseHandler responseHandler) 
void get(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) 
void get(String url, AsyncHttpResponseHandler responseHandler) 
void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) 

あなたがGETリクエスト内の永続的なCookieを送信例を与えることができれば、私は幸せになります。

+1

はすでにクッキーを追加しています。 client.get()の前に追加してください。 – robotoaster

答えて

3

独自のPersistentCookieStoreインスタンスを作成しているため、作成したmyCookieStoreインスタンスを使用してください。 @robotoasterのように、get()の前に追加します。

OR

この

HttpContext httpContext = httpClient.getHttpContext(); 
CookieStore cookieStore = (CookieStore) httpContext.getAttribute(ClientContext.COOKIE_STORE); 

が続いhttp://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/CookieStore.htmlで指示に従ってください。

出典:あなたはclient.setCookieStore(myCookieStore)を設定するとき(ストレートloopjから)Cookies in loopj for android

関連する問題