単純なログインを行っていますが、リダイレクト中に、正しくアクセスするために必要な3つのCookieのうち2つしか持っていないことに気付きました。他のCookieをキャプチャしてまとめましたが、何らかの理由でヘッダーをその場で変更できませんか?
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSHTTPURLResponse *)response {
NSURL* redirected_url = [request URL];
NSString* querystr = [redirected_url absoluteString];
if (response != nil) {
NSArray* zzzz = [NSHTTPCookie
cookiesWithResponseHeaderFields:[response allHeaderFields]
forURL:[NSURL URLWithString:@""]];
if ([zzzz count] > 0) {
if ([querystr isEqualToString:@"https://www.localhost.com/specificurl.aspx"]) {
NSMutableArray* actualCookies = [[NSMutableArray alloc] init];
NSHTTPCookie* obj = [self.tmpCookies objectAtIndex:0];
[actualCookies addObject:obj];
[actualCookies addObject:zzzz];
NSArray* authToken = [[NSArray alloc] initWithArray:actualCookies];
//BLOWS UP HERE ?? NSDictionary* headers = [NSHTTPCookie requestHeaderFieldsWithCookies:authToken];
//[request setAllHTTPHeaderFields:authToken];
[viewController setAuthCookieAfterValidLogin:zzzz];
}
}
}
return request;
}
一般的な考え方は、このヘッダーを組み合わせたCookieの値を持つように設定することです