在我的应用程序中,我想使用WKWebView进行登录,然后对服务器的所有进一步请求都已完成。
我可以使用WKWebView成功登录。在它的成功我得到会话信息。我之前使用UIWebView实现了它并且它正常工作。我所有进一步的Web服务调用都在UIWebView中正常工作。
现在,当我使用WKWebView实现登录时,它已成功登录,但是当我点击不同的链接(URL)时,它每次都给我注销响应,而我正在尝试使用Cookie调用服务,并且它没有给我正确的响应作为会话信息没有通过。
有什么办法,我可以存储WKWebView的会话信息
任何帮助将不胜感激。请帮忙!
以下是设置Cookie的代码: -
*{
// Set iPad cookie for our requests
NSString* dotDomain = [NSString stringWithFormat:@".%@", CookieDomain];
NSDictionary* newCookieDict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:
dotDomain, NSHTTPCookieDomain,
@"iPad", NSHTTPCookieName,
@"/", NSHTTPCookiePath,
@"1", NSHTTPCookieValue,
@"2040-1-1 00:00:00 -0700", NSHTTPCookieExpires,
nil];
NSHTTPCookie* newCookie = [NSHTTPCookie cookieWithProperties:newCookieDict];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:newCookie];
}
// Don't block cookies, so dosespot will work
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];*
这是我的Request HTTP Header和Response HTTP Header: -
*Request HTTP Header : {
"Accept-Encoding" = gzip;
Cookie = "cookie_test=1; cookie_test=1; CAKEPHP=jkn36knqoul2f14rebb8k5h882; iPad=1";
"User-Agent" = "iPad App";
} *
**Response HTTP Header : {
Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 5668;
"Content-Type" = "text/html";
Date = "Tue, 10 May 2016 13:58:14 GMT";
"Keep-Alive" = "timeout=5, max=99";
Server = "Apache/2.2.22 (Ubuntu)";
Vary = "Accept-Encoding";
"X-Powered-By" = "PHP/5.3.10-1ubuntu3.15";
} **