1

I am developing the servlets for a native ios application.. Now I placed some of the things in session to be retrieved later on, this thing is now working perfect as far as we run the site in pc browser, but my concern is that since pc browser always pass the session id in every request in background to fulfill the response(using the headers and special keys), how that can be achieved in ios native app, I mean I will send the sessionId at the starting when session is created for the app and will tell the ios developer to send that key(sessionId) while sending the request and get the exact data associated with that sessionId in the server.

So is it possible to achieve that or I have to change the server code(which I don't want at all.. ;( )......

please shed some light on it....thanks... in advance...............Ankur

Ankur Verma
  • 5,793
  • 12
  • 57
  • 93

3 Answers3

1

I know you can do it with a HTTP Cookie. That is store a cookie in server side and retrieve it using ASIHTTP/AFNetworking Frameworks,

FYI - Objective-C Asynchronous Web Request with Cookies

FYI - http://brainwashinc.wordpress.com/2009/12/16/http-cookie-support-iphone/

For httpsession id you can retrieve it with javascript. using the following code.

Store the below as a session.js and add it in assets, within the iOS App.

<script type = "text/javascript">
function GetSession()

{
var SessionID = "<%=Session.SessionID%>";

alert(SessionID);
return SessionID;
}

</script>

for loading a js from resources - Loading javascript into a UIWebView from resources

You can load the javascript in webview and send it as a param to another request to your server if you want.

I think this is one possible solution to your problem. I am unaware if there are any HTTPSession ways of doing it unless there's a keep-alive connection.

Community
  • 1
  • 1
Lalith B
  • 11,843
  • 6
  • 29
  • 47
1

The iOS application should automatically handle your cookies, assuming it's using NSURLConnection. It won't need any special code to handle it.

MattR
  • 6,908
  • 2
  • 21
  • 30
1

ASIHttpRequest automatically manages it for you. See this,

[request setUseSessionPersistence:YES];

in this link

nithinreddy
  • 6,167
  • 4
  • 38
  • 44
  • 2
    ASIHttp has discontinued support. Check AFNetworking as alternative. http://stackoverflow.com/questions/10984374/how-to-manage-sessions-with-afnetworking – Lalith B Aug 13 '12 at 11:25