在Android的维护会话

在Android的维护会话

本文介绍了在Android的维护会话(应用程序保持验证服务器端)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立在Android的登录应用程序中,我打一个网址(用户名和密码),高达的一部分,工作正常,但在那之后,每当我打一个url(一旦用户进行身份验证),它返回任何结果(即一个错误消息像请登录第一)。然而,它工作正常,在非常相似的iPhone应用程序和浏览器。

I am building a login application in android in which i am hitting a url(with username and password) upto that part it works fine but after that whenever I am hitting a url(once the user is authenticated) , it return nothing(i.e. a error message like please login first). However it works fine in very similar iphone app and on browser.

我的地方,它是phpSessionId的误差(即会话被破坏了进一步要求),如果我们希望我们的Andr​​oid应用程序,以保持在服务器端进行身份验证,我们需要获取的第一个连接后,该ID,然后发送这在我们所有的后续请求的报头。

I got somewhere that it is the error of phpSessionId(i.e. the session is destroyed for further request) and If we want our Android application to stay authenticated on the server side we need to fetch that id after the first connection and then send it in the headers of all our subsequent requests.

但问题是,我无法从第一连接的报头获得的sessionId和与连同报头还请求将其发送。

But the problem is that I am unable to get the sessionId from header of the first connection and sending it with further request along with the header.

请给我一些codeS或链接正确完成任务。谢谢。

Please give me some codes or links to complete the task properly.Thanks.

推荐答案

最后,我在Android中解决了会话处理的问题。Android的不能处理的会议本身(这一个简单的浏览器可以),所以我们必须明确地处理它。我改变了code HTTP连接位。创建实例 DefaultHttpClient 在连接时建立的第一个活动。

Finally I solved the issue of session handling in Android.Android cant handle the session itself(which a simple browser can) so we have to handle it explicitly.I changed the code for http connection a bit.Created an instance of DefaultHttpClient in the first Activity when connection established.

public static DefaultHttpClient httpClient;

第一次连接时,我做了以下内容:

For the first time connection,I did the following:

URL url=new URL(urlToHit);
LoginScreen.httpClient = new DefaultHttpClient(); //LoginScreen is the name of the current Activity

HttpPost httppost = new HttpPost(url.toString());
HttpResponse response = LoginScreen.httpClient.execute(httppost);

xr.parse(new InputSource(url.openStream())); //SAX parsing

现在所有进一步的连接我用同样的的HttpClient 例如,在接下来的活动:

Now for all further connections I used the same httpClientFor example in the next activity:

URL url=new URL(urlToHit);

HttpPost httppost = new HttpPost(url.toString());
HttpResponse response = LoginScreen.httpClient.execute(httppost);

// Log.v("response code",""+response.getStatusLine().getStatusCode());

// Get hold of the response entity
HttpEntity entity = response.getEntity();

InputStream instream = null;

if (entity != null) {
    instream = entity.getContent();
}
xr.parse(new InputSource(instream)); //SAX parsing

希望这将帮助你太解决会议问题的Andr​​oid

这篇关于在Android的维护会话(应用程序保持验证服务器端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:11