Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes HTTP redirect issues when posting a second time #92

Merged
merged 6 commits into from Jul 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions QuickRadar/QRRadarSubmissionService.m
Expand Up @@ -116,10 +116,14 @@ - (void)submitAsyncWithProgressBlock:(void (^)())progressBlock completionBlock:(
* Page 1: login page *
**********************/

self.submissionStatusText = @"Fetching RadarWeb signin page";
self.submissionStatusText = @"Fetching RadarWeb signin page";
QRWebScraper *loginPage = [[QRWebScraper alloc] init];
loginPage.URL = [NSURL URLWithString:@"https://idmsa.apple.com/IDMSWebAuth/classicLogin.html?appIdKey=77e2a60d4bdfa6b7311c854a56505800be3c24e3a27a670098ff61b69fc5214b&sslEnabled=true&rv=3"];


// Start with a clean slate. Should be enough to just delete the "myacinfo" cookie,
// to fix re-authentication issues, but let's rather make it more predictable by purging all.
[loginPage deleteCookies];

if (![loginPage fetch:&error])
{
dispatch_sync(dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -425,6 +429,14 @@ - (void)submitAsyncWithProgressBlock:(void (^)())progressBlock completionBlock:(
});
}

// DEBUG: Enable to prevent posting dummy radars if debugging authentication.
#if 0
dispatch_sync(dispatch_get_main_queue(), ^{
self.submissionStatusValue = submissionStatusFailed;
completionBlock(NO, [NSError errorWithDomain:@"QRDebugDomain" code:0 userInfo:@{NSLocalizedDescriptionKey: @"Manually canceled in `submitAsyncWithProgressBlock:`!"}]);
});
return;
#endif


/***************************
Expand Down
3 changes: 3 additions & 0 deletions QuickRadar/QRWebScraper.h
Expand Up @@ -27,6 +27,9 @@
/* A synchronous method */
- (BOOL)fetch:(NSError**)error;

/* Deletes any cookies currently present. Set the URL before invoking this method. */
- (BOOL)deleteCookies;

- (NSDictionary*)stringValuesForXPathsDictionary:(NSDictionary*)dict error:(NSError**)error;

@end
17 changes: 17 additions & 0 deletions QuickRadar/QRWebScraper.m
Expand Up @@ -167,6 +167,23 @@ - (BOOL)fetch:(NSError**)returnError;
}


- (BOOL)deleteCookies
{
NSURL *url = self.URL;
NSAssert(url != nil, @"Set the URL before invoking this method.");

BOOL deleted = NO;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray<NSHTTPCookie *> *cookies = [storage cookiesForURL:url];
for (NSHTTPCookie *cookie in cookies)
{
[storage deleteCookie:cookie];
deleted = YES;
}
return deleted;
}


- (NSDictionary*)stringValuesForXPathsDictionary:(NSDictionary*)dict error:(NSError**)retError;
{
// NSLog(@"Data %@", [[NSString alloc] initWithData:self.returnedData encoding:NSUTF8StringEncoding]);
Expand Down