开发者

Handling session and cookies for log in on android app using titanium

开发者 https://www.devze.com 2023-04-04 19:07 出处:网络
hi I am working on Android application development.I have developed small application.after logging my application capture authentication token.But I am not storing any user name name password or auth

hi I am working on Android application development.I have developed small application.after logging my application capture authentication token.But I am not storing any user name name password or authentication token.after logging my application; when I make request for accessing data from remote server it again ask me for log in.I want to access my data for further processing. I used following code.

for sending logging request: It gives me Authentication token(app.js)

var xhr = Titanium.Network.create开发者_如何学运维HTTPClient();
xhr.onerror = function()
{
Titanium.API.info('error');
alert(JSON.parse(this.responseText).error);
};
xhr.open('POST','http://192.168.1.2:3000/users/sign_in.json');
var params = {'user[login]':username.value,'user[password]':password.value};
Ti.API.info('Params'+JSON.stringify(params));
xhr.send(params);     

for accessing data:(main.js)

var xhr = Titanium.Network.createHTTPClient();
xhr.onerror = function()
{
Titanium.API.info('error');
alert(JSON.parse(this.responseText).error);
};
xhr.open('GET','http://192.168.1.2:3000/lists.json');
var params = {'[id]':'32'}; 
Ti.API.info('Params'+JSON.stringify(params));
xhr.send(params);

But it shows error that log in first.Is there any way to handle this problem.


you will have to send the cookie/session id in the header of every request so that the server can identify you and give your data back -- you can store the session id , cookie or whatever the server sends you for authentication in a shred preference for further use or if you don't want to store you can send it though intent -- in a bundle or as string

and you will have to add it in the header as per the servers requirement

0

精彩评论

暂无评论...
验证码 换一张
取 消