Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android到Drupal cookie传输Q2_Android_Drupal_Cookies_Session Cookies - Fatal编程技术网

Android到Drupal cookie传输Q2

Android到Drupal cookie传输Q2,android,drupal,cookies,session-cookies,Android,Drupal,Cookies,Session Cookies,之前,我在上问了一个关于将cookies从Android应用程序发送回Drupal网站的问题,我得到了一个非常好的答案。整个想法是实现持久的客户机-服务器交互 我按照指示调整了代码,但仍然无法正常工作。我的代码调整如下: protected Void doInBackground(Void... params) { // TODO Auto-generated method stub HttpResponse response; HttpClie

之前,我在上问了一个关于将cookies从Android应用程序发送回Drupal网站的问题,我得到了一个非常好的答案。整个想法是实现持久的客户机-服务器交互

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

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

}
受保护的Void doInBackground(Void…params){
//TODO自动生成的方法存根
HttpResponse响应;
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://testsite.com/testpoint/node/");
BasicHttpContext basicContext=新的BasicHttpContext();
org.apache.http.client.CookieStore CookieStore=新的BasicCookieStore();
basicContext.setAttribute(ClientContext.COOKIE\u存储,cookiestore);
basicContext.setAttribute(USERPREFERENCES.getString(COOKIE\u NAME,“”),USERPREFERENCES.getString(COOKIE\u VALUE,“”);
//USERPREFERENCES.getString(CO0OKIE_NAME,“”),USERPREFERENCES.getString(COOKIE_值,“”)
//TODO自动生成的方法存根
试一试{
List nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“节点[标题],“应用程序中的示例节点”);
添加(新的BasicNameValuePair(“节点[类型],“故事”);
添加(新的BasicNameValuePair(“节点[正文],“示例应用程序节点正文内容”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
//执行HTTP post请求
//HttpResponse
response=httpClient.execute(httpPost,basicContext);
Log.i(“似乎有效”,response.toString());
Log.v(“CODE”,httpPost.getRequestLine().toString()+“-”+response.toString());
}捕获(例外e){
e(“HTTP-ERROR:node creation”,e.toString());
}
返回null;
}
@凌驾
受保护的void onPostExecute(void结果){
//TODO自动生成的方法存根
super.onPostExecute(结果);
//Toast.makeText(getApplicationContext(),“创建节点线程返回!”,Toast.LENGTH\u LONG.show();
Toast.makeText(getApplicationContext(),“测试头:Cookie:”+USERPREFERENCES.getString(Cookie\u名称“”+”,“+USERPREFERENCES.getString(Cookie\u值“”),Toast.LENGTH\u LONG).show();
}
}
基本上,我的cookie名称和值存储在我的共享首选项USERPREFERENCES.getString(cookie\u name,“”)和USERPREFERENCES.getString(cookie\u value,“”)中。 我正试图将这些信息发送回去,这样当这个函数执行并在我的Drupal站点上成功创建一个新的故事节点时,作者就会被识别为从Android应用程序注册并登录的用户

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


有人能帮我吗?

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

当我遇到这样的问题时,我需要一种方法来查看与我的应用程序之间的请求头是什么样子的

我通常使用Charles(很棒的工具)来实现这一点。不,我和公司没有任何联系,这只是一个很好的工具

Charles中有一个称为反向代理的功能,基本上它允许您通过Charles将流量反弹到drupal服务器,并且您可以在流量流入和流出应用程序时对其进行检查

使用charles,您可以嗅探来自web浏览器的良好请求,然后您可以嗅探来自android应用程序的请求。比较这两者,你可以看到你的应用程序在哪里对请求头进行了糟糕的塑造

调试阶段如下所示:

设置好Charles后,点击drupal服务器几次,检查从浏览器中看到的请求/响应的结构

然后从android应用程序中点击几次你的服务,并注意差异。也许cookie没有通过,也许它的格式不正确,也许头还有其他原因。这将让您看到为了让Drupal接受请求,您需要做些什么

还有一些说明吗-

反向代理将允许您检查来自手机和drupal站点的流量(包括标题,这样您就可以准确地看到发送的cookie)。要设置反向代理,您需要转到“代理”菜单下的“反向代理”并添加一个新的反向代理-该代理将接收指向您的localhost:PORTNUM的流量,并将其重新路由到drupal服务器。它将记录双向通信。此外,您还可以在FireFox上点击drupal服务几次,观察web应用程序如何进行身份验证,从而了解您的目标


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

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

当我遇到这样的问题时,我需要一种方法来查看与我的应用程序之间的请求头是什么样子的

我通常使用Charles(很棒的工具)来实现这一点。不,我和公司没有任何联系,这只是一个很好的工具

Charles中有一个称为反向代理的功能,基本上它允许您通过Charles将流量反弹到drupal服务器,并且您可以在流量流入和流出应用程序时对其进行检查

使用cha