LoopJ AndroidAsyncHttp并请求cookie
发布时间:2020-12-14 23:22:58 所属栏目:资源 来源:网络整理
导读:关于LoopJ AndroidAsyncHttp examples我发这样的获取请求: final TextView text = (TextView) findViewById(R.id.textView); AsyncHttpClient client = new AsyncHttpClient(); client.get("http://example.com/mypage/",new AsyncHttpResponseHandler() {
关于LoopJ
AndroidAsyncHttp
examples我发这样的获取请求:
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); } }); 我还添加了cookies: PersistentCookieStore myCookieStore = new PersistentCookieStore(this); client.setCookieStore(myCookieStore); BasicClientCookie newCookie = new BasicClientCookie("id",17882); myCookieStore.addCookie(newCookie); 但在提出GET请求时,如何在请求对象中发送我的cookie? 关于documentation客户有这些方法签名: void get(Context context,String url,AsyncHttpResponseHandler responseHandler) void get(Context context,Header[] headers,RequestParams params,AsyncHttpResponseHandler responseHandler) void get(String url,AsyncHttpResponseHandler responseHandler) 如果你能举一个在GET请求中发送持久性cookie的例子,我会很高兴. 解决方法
由于您要创建自己的PersistentCookieStore实例,因此只需使用您创建的myCookieStore实例.就像@robotoaster所说,在get()之前添加它.
要么 做这个 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的说明操作. 资料来源:Cookies in loopj for android(直接来自loopj) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |