如何SESSION_ID保存为cookie的值,并将其在Android中发送给服务器 [英] How to save session_id as cookie value and send it to server in android

查看:119
本文介绍了如何SESSION_ID保存为cookie的值,并将其在Android中发送给服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我使用的web服务的调用上的应用程序的工作,

Well, I am working on a app using webservices calls,

我打电话给我的登录web服务如下:

I am calling my Login webservice as follows

String url = "http://mydomaim.com/login.php";

        UserFunctions userFunction = new UserFunctions();
        JSONObject json = userFunction.loginUser(userEmail, password, url);

它工作正常,并给我答复,如下图所示。

it works fine and send me response as show below

{
 "userName":"a",
   "login_success":1,
   "user_id":"3",
   "session_id":"1067749aae85b0e6c5c5e697b61cd89d",
   "email":"a"
}

我解析这个响应,并成功并获得一个变量的会话ID。 现在,我必须调用其它Web服务附加这些SESSION_ID作为cookie的值。

I parse this response, and successfully and got the session id in a variable. Now i have to call an other webservice appending this session_id as cookie value.

如何存放 SESSION_ID 在我的Andr​​oid设备中的我的cookie值和调用其它Web服务。

How to store the session_id as the my cookie value in my android device and call other webservice.

下面是我的PHP Web服务code。

here is my php webservice code.

请帮忙。

推荐答案

试试这个,当用户登录调用此请求。

Try this, When login Call this request.

DefaultHttpClient httpClient = new DefaultHttpClient();
        String paramString = URLEncodedUtils.format(params, "utf-8");
        url += "?" + paramString;
        HttpGet httpGet = new HttpGet(url);
        HttpResponse httpResponse = httpClient.execute(httpGet);

        List<Cookie> cookies = httpClient.getCookieStore().getCookies();
        for (Cookie cookie : cookies) {
            System.out.println("Cookie: " + cookie.toString());

            if (cookie.getName().contains("PHPSESSID"))
                guid = cookie.getValue();

        }

        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

这篇关于如何SESSION_ID保存为cookie的值,并将其在Android中发送给服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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