Maintaining session in after closing UIWebView

2019-06-05 10:27发布

问题:

I have an application which has a login page resides on the application server. So I open a UIWebView to handle the login. After then I want to switch to the UIView and make API calls using ASIHttp library (others may also be acceptable). The problem is; after I login server keeps session object for authentication purpose, so when I close the UIWebView and switch to a UIView and make an API call, it fails. I believe, somehow I need to maintain session object (set after login) in the API calls. How can I achieve this?

回答1:

Here are the steps I followed:

  • Extract the cookies in UIWebView using NSHTTPCookieStorage class.
  • Send it back using ASIHTTPRequest setRequestCookies: method for the subsequent calls