Created
April 15, 2011 00:32
-
-
Save toranb/920896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSHTTPURLResponse *)response { | |
| NSURL* redirected_url = [request URL]; | |
| NSString* querystr = [redirected_url absoluteString]; | |
| if (response != nil) { | |
| NSArray* authToken = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@""]]; | |
| if ([authToken count] > 0) { | |
| NSString* dashboard_url = @"https://www.memberselfservice.com/frmDashBoard.aspx"; | |
| if ([querystr isEqualToString:dashboard_url]) { | |
| NSMutableArray* actualCookies = [[NSMutableArray alloc] init]; | |
| NSUInteger i, count = [authToken count]; | |
| for (i = 0; i < count; i++) { | |
| //the 2 cookies we pull from this redirect are | |
| // 1.) Company_ID token to identify the customer site | |
| // 2.) .ASPXAUTH token that proves we have a valid login for this session | |
| NSHTTPCookie* currentCookie = [authToken objectAtIndex:i]; | |
| [actualCookies addObject:currentCookie]; | |
| [currentCookie release]; | |
| } | |
| //for some odd reason we lose the ASP.NET_SessionId cookie so | |
| //we manually add it from the view state request made previously | |
| NSHTTPCookie* obj = [self.tmpCookies objectAtIndex:0]; | |
| [actualCookies addObject:obj]; | |
| //now we have the cookies required to do the http GET request that will show the dashboard markup | |
| NSDictionary* headers = [NSHTTPCookie requestHeaderFieldsWithCookies:actualCookies]; | |
| NSURL* url = [NSURL URLWithString:dashboard_url]; | |
| NSMutableURLRequest* dashboardHttpRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; | |
| [dashboardHttpRequest setHTTPMethod:@"GET"]; | |
| [dashboardHttpRequest setAllHTTPHeaderFields:headers]; | |
| [dashboardHttpRequest setValue:@"https://www.memberselfservice.com/Default.aspx?Company_ID=500066" forHTTPHeaderField: @"Referer"]; | |
| [viewController setAuthCookieAfterValidLogin:authToken]; | |
| return dashboardHttpRequest; | |
| } | |
| } | |
| } | |
| return request; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment