如何比较cookie域和NSURL?

时间:2013-04-23 11:20:39

标签: ios objective-c

我只想从cookie获取访问令牌,如果条件我想要比较cookie域和给定URL。我正在尝试使用以下代码:

- (void)viewDidLoad 
{
    [super viewDidLoad];

    NSURL *url = [[NSURL alloc] initWithString:websiteUrl];

    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [webView loadRequest:requestObj];  
}

- (NSString*)getTokenFromCookie {

    NSHTTPCookie *cookie;

    NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];

    for (cookie in [cookieJar cookies]) {

        NSLog(@"%@",cookie);

        //Here to compare cookie domain and above given URL

        if ([[cookie domain] isEqualToString:domain]) {

            if ([[cookie name] isEqualToString:@"oauth_token"]) {

                return [cookie value];
            }
        }
    }
    return nil;
}

0 个答案:

没有答案