Android版Drupal的饼干转移 [英] Android to Drupal cookie transfer

查看:116
本文介绍了Android版Drupal的饼干转移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以请赐教,我怎么会从我的Andr​​iod应用程序发送的Drupal登录cookie信息反馈给我的Drupal网站?

can someone please enlighten me on how I might send Drupal login cookie information from my Andriod app back to my Drupal site?

下面是个code,我用我的尝试:

Below is th code I am using in my attempts:

HttpResponse response;
        HttpClient httpClient   =   new DefaultHttpClient();
        HttpPost httpPost       =   new HttpPost("http://test2.icerge.com/testpoint/node/");
        **httpPost.addHeader("Cookie: " + USERPREFERENCES.getString(COOKIE_NAME, ""), " "+USERPREFERENCES.getString(COOKIE_VALUE, ""));**

Toast.LENGTH_LONG).show();
                // TODO自动生成方法存根
                尝试{
                    清单namevaluepairs中=新的ArrayList();
                    nameValuePairs.add(新BasicNameValuePair(节点[标题],从应用程序样本节点));
                    nameValuePairs.add(新BasicNameValuePair(节点【类型】,故事));
                    nameValuePairs.add(新BasicNameValuePair(节点[正文],示例应用程序节点主体内容));
                    httpPost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));

Toast.LENGTH_LONG).show(); // TODO Auto-generated method stub try{ List nameValuePairs = new ArrayList(); nameValuePairs.add( new BasicNameValuePair("node[title]", "sample node from app") ); nameValuePairs.add( new BasicNameValuePair("node[type]", "story") ); nameValuePairs.add( new BasicNameValuePair("node[body]", "sample app node body content") ); httpPost.setEntity( new UrlEncodedFormEntity(nameValuePairs));

                response    =   httpClient.execute(httpPost);

                Log.i("SEEMS TO WORK", response.toString());
                Log.v("CODE", httpPost.getRequestLine().toString() + " - " + response.toString());

            }catch(Exception e){
                Log.e("HTTP-ERROR: node creation", e.toString());
            }

我使用的是httpPost和addHeader行送我的饼干,但nojoy。

I am using the "httpPost addHeader" line to send my cookie, but nojoy.

有人请告诉我关于这个问题,好吗?

Can someone please direct me on this issue, please?

推荐答案

我不相信HttpClient的默认管理饼干。所以,你需要建立一个cookie存储,将其绑定在HTTP上下文,然后使用职位的背景下,像这样

I do not believe that the HttpClient manages cookies by default. So you need to set up a cookie store, bind it the HTTP Context, and then use the context in POSTs, like this

    mHttpContext = new BasicHttpContext();
    mCookieStore = new CookieStore();       
    mHttpContext.setAttribute(ClientContext.COOKIE_STORE, mCookieStore);
    ...
    HttpResponse response = mHttpClient.execute(mRequest, mHttpContext);

一旦到位,从上响应的Drupal站点发送的任何cookies将被自动包含在后续的请求。

Once that is in place any cookies that sent from the Drupal site on responses will be automatically included on subsequent requests.

如果你有兴趣看到由你的CookieStore总是可以做举行什么饼干

If you are interested to see what cookies are held by the CookieStore you can always do

List<Cookie> cookies = mCookieStore.getCookies();

这篇关于Android版Drupal的饼干转移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆