Android到Drupal cookie转移Q2 [英] Android to Drupal cookie transfer Q2

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

问题描述

以前,我在 Android到Drupal Cookie传输中提出了一个关于发送Cookie的问题我的Android应用程序回到我的Drupal网站,我有一个非常好的答案。整个想法是启用持久的客户端 - 服务器交互。

Previously I asked a question at Android to Drupal cookie transfer about sending cookies from my Android app back to my Drupal website to which I got a very good answer. The entire idea is to enable a persistent Client-Server interaction.

我按照指示调整了代码,但是我仍然无法使事情正常工作。我的代码调整如下:

I adjusted my code as was directed but I still can not get things working right. My code adjustments are below:

protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub

        HttpResponse response;
        HttpClient httpClient   =   new DefaultHttpClient();
        HttpPost httpPost       =   new HttpPost("http://testsite.com/testpoint/node/");

        BasicHttpContext basicContext   =   new BasicHttpContext();
        org.apache.http.client.CookieStore cookiestore  =   new BasicCookieStore();
        basicContext.setAttribute(ClientContext.COOKIE_STORE, cookiestore);
        basicContext.setAttribute(USERPREFERENCES.getString(COOKIE_NAME, ""), USERPREFERENCES.getString(COOKIE_VALUE, "") );
        //USERPREFERENCES.getString(CO0OKIE_NAME, ""), USERPREFERENCES.getString(COOKIE_VALUE, "")

            // TODO Auto-generated method stub
            try{
                List<NameValuePair> nameValuePairs  =   new ArrayList<NameValuePair>();
                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));

                //Execute HTTP post request
                //HttpResponse 
                response    =   httpClient.execute(httpPost, basicContext);

                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());
            }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        //Toast.makeText(getApplicationContext(), "Create Node thread returning!", Toast.LENGTH_LONG).show();
        Toast.makeText(getApplicationContext(), "Testing header: Cookie: " + USERPREFERENCES.getString(COOKIE_NAME, "") +","+ USERPREFERENCES.getString(COOKIE_VALUE, ""), Toast.LENGTH_LONG).show();
    }

}

基本上,我的cookie名称和值存储在我的共享首选项USERPREFERENCES.getString(COOKIE_NAME,)和USERPREFERENCES.getString(COOKIE_VALUE,)中。
我正在尝试将该信息发送回来,以便在此功能执行并在Drupal网站上成功创建新的故事节点时,作者被认为是从Android应用程序注册并登录的用户。

Basically, my cookie name and value are stored in my shared preferences USERPREFERENCES.getString(COOKIE_NAME, "") and USERPREFERENCES.getString(COOKIE_VALUE, ""). I am trying to send that information back so that when this function executes and successfully creates a new story node on my Drupal site, the author is recognized as the user who registered and signed in from the Android app.

目前,节点被创建,但用户是匿名的。因此,我需要发回Drupal的用户Cookie信息。

At present, the node is created but the user is "anonymous". Hence, I need to send back Drupal's user cookie information.

任何人都可以帮助我吗?

Can anyone please assist me?

推荐答案

这不一定是您的问题的代码解决方案,但可能会有所帮助。

This is not necessarily a code solution to your problem, but may be helpful.

当我遇到这样的问题时,我需要一个我的方法来看看我的应用程序的请求标头是什么样子。

When I'm approaching problems like this I need a way to see what the request headers to and from my app look like.

我通常使用Charles(很棒的工具) http://www.charlesproxy.com/ 为此。不,我没有与公司有任何联系,这只是一个很好的工具。

I typically use Charles (great tool) http://www.charlesproxy.com/ for this. And no I don't have any connection to the company, it's just a great tool.

Charles有一个功能叫做反向代理,基本上它允许你弹跳通过查尔斯流量到你的drupal服务器,你可以检查它流入和从您的应用程序。

There's a feature in Charles called a reverse proxy and basically it allows you to bounce traffic through Charles to your drupal server and you can inspect it as it flows to and from your app.

使用查尔斯你可以嗅到一个良好的请求从您的网络浏览器看起来喜欢,然后你可以嗅到你的Android应用程序的请求的样子。比较两个,你可以看到你的应用程序正在严重塑造请求头。

Using charles you can sniff what a good request from your web browser looks like and then you can sniff what the requests from your android app look like. Compare the two and you can see where your app is badly shaping the request headers.

调试阶段如下所示:

一旦你设置了Charles,你的drupal服务器几次,并检查您从浏览器看到的请求/响应的结构。

Once you've got Charles set up, hit your drupal server a couple of times and inspect the structure of the request/response that you're seeing from the browser.

然后从Android应用程序中点击您的服务几次,并记下差异。也许cookie不会通过,也许是畸形的,也可能还有其他的标题。这将让您看到您需要拍摄什么才能让Drupal接受请求。

Then hit your service a couple of times from the android app and note the differences. Maybe the cookie isn't going through, maybe it's malformed, maybe there's something else about the headers. This will let you see what you need to shoot for in order to get Drupal to accept the requests.

更多说明 -

逆向代理将允许您检查来自您手机的流量,并进入您的drupal站点(包括标题,以便您准确地看到正在发送的Cookie)。要获得反向代理设置,您需要转到代理菜单下的代理,并添加一个新的反向代理 - 代理将使您的本地主机:PORTNUM引导流量并将其重新路由到您的drupal服务器。它将记录双向通信。此外,您可以从FireFox打几次服务,并观看网络应用程序的身份验证,以了解您的目标。

The reverse proxy will allow you to inspect traffic coming from your phone and going to your drupal site (including headers so you should see exactly what cookies are being sent). To get the reverse proxy set up, you'll need to go to reverse proxies under the proxy menu and add a new reverse proxy - the proxy will take traffic directed at your localhost:PORTNUM and re-route it to your drupal server. It'll log communications going in both directions. Also, you can hit your drupal service a couple of times from FireFox and watch how a web app authenticates so you know what you're aiming for.

为了看到电话流量,您需要确保您的手机已连接到与计算机相同的网络。重新编写您的电话代码,以便将其请求发送到本地计算机。如果您已将所有配置正确配置,Charles将弹出一条消息,询问您是否可以连接手机。之后,您可以看到从Web服务器发送的头文件有什么不同。

In order to see phone traffic, you'll need to be sure your phone is connected to the same network as your computer. Re-write your phone code so that it addresses its web requests to your local computer. If you've got everything configured correctly then Charles will pop up a messages asking you if it's ok to allow your phone to connect. After that you can see what's different about the headers you're sending from what the web server is sending.

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

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