In my application, I am trying to login through a UIWebView. Upon successful use of cookies, the login value is set to NSHTTPCookieStorage . UIWebView has several pages of my applications open.
When a request for a specific web page is sent, it checks whether the user is registered or not based on cookies.
I verified that cookies are present in NSHTTPCookieStorage , but are not valid cookies on the server. That is, he considers the user as a registered user.
My code for loading UIWebView is as follows:
let url = serverURL + urlString let urlRequest = NSMutableURLRequest(URL: NSURL(string: url)!) webPage.loadRequest(urlRequest)
Even I tried using NSURLSession and set cookies as HTTPHeaderField. Below is my code:
let URLRequest: NSMutableURLRequest = NSMutableURLRequest(URL: NSURL(string: url)!) let cookies = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookiesForURL(NSURL(string: serverURL)!) for cookie in cookies!{ URLRequest.setValue(cookie.value, forHTTPHeaderField: cookie.name) } let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration() let session = NSURLSession(configuration: sessionConfig, delegate: self, delegateQueue: nil) let task = session.downloadTaskWithRequest(URLRequest) task.resume()
It works correctly for several cases. I cannot find what could be the problem for cookies.
Any help would be appreciated.
Thank you in advance
source share