如何将session_id保存为cookie值并将其发送到Android中的服务器? [英] How to save session_id as cookie value and send it to server in Android?
本文介绍了如何将session_id保存为cookie值并将其发送到Android中的服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用网络服务调用来开发应用程序.
I am working on a app using web services 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的变量. 现在,我必须调用另一个将这个session_id附加为cookie值的web服务.
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.
问题
如何在我的Android设备中将session_id
作为我的cookie值存储并调用其他Web服务?
How to store the session_id
as the my cookie value in my Android device and call other web service?
推荐答案
尝试此操作,登录时调用此请求.
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屋!
查看全文