In my iOS application, I am incorporating html content within a webview. This html is a login page where user credentials are sent to the server via ajax and an authentication success or failure response is received. The response includes a cookie in the Set-Cookie
header field that I can extract on the Objective-C side as follows:
NSDictionary* headers = [(NSHTTPURLResponse *)response allHeaderFields];
NSString *strCookies = [headers valueForKey:@"Set-Cookie"];
NSLog(@"cookies -> %@", strCookies);
The response also contains a responseText
that I use within the browser like this:
Ajax("/login", "POST", { onsuccess : function(response){
/* Do HTML stuff with response */ }
});
However, I require the cookie for making subsequent ajax requests after the login page. Despite this, the cookie does not get set in the webview browser. When attempting to access it using document.cookie
, an empty string is returned. Although I can display all response headers using xhr.getAllResponseHeaders()
, I am unable to retrieve the Set-Cookie
field from the xhr object.
Is there a way to set the cookie inside the webview, or do I have no option but to conduct all ajax requests through Obj-C?