
我想知道如何让webVIEw意识到auth cookie就在那里,所以它不会每次都继续提示用户进行身份验证.解决方法 您可以使用NSURLConnection类执行http请求以登录网站,并检索cookie.要执行请求,只需创建一个NSURLConnection实例并为其分配一个委托对象.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.Google.com/"]];NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
然后,实现委托方法.
- (voID)connection:(NSURLConnection *)connection dIDReceiveResponse:(NSURLResponse *)response{ NShttpURLResponse *httpResponse = (NShttpURLResponse *)response; NSDictionary *fIElds = [httpResponse allheaderFIElds]; Nsstring *cookie = [fIElds valueForKey:"Set-cookie"]; // It is your cookie} 保留或复制cookie字符串.如果要执行其他请求,请将其添加到NSURLRequest实例的http标头中.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.Google.com/"]];[request addValue:cookie forhttpheaderFIEld:"cookie"];
要随时可以调用此方法删除cookie:
NShttpcookiestorage *cookieStorage = [NShttpcookiestorage sharedhttpcookiestorage]; for (NShttpcookie *each in [[[cookieStorage cookiesForURL:YOUR_URL] copy] autorelease]) { [cookieStorage deletecookie:each]; } 总结 以上是内存溢出为你收集整理的iphone – iOS UIwebView Auth Cookies全部内容,希望文章能够帮你解决iphone – iOS UIwebView Auth Cookies所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)