/gist:04c477231bae3c27b7dc Secret
Created
January 26, 2012 21:04
Star
You must be signed in to star a gist
Download Query
This file contains 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
- (void)doDownloadQuery:(JsonQueryParam *)queryParam withRequest:(id)request andProgressDeleate:(id)progressDelegate | |
{ | |
param = [queryParam retain]; | |
NSData *postData = nil; | |
NSString *postLength = nil; | |
NSString *method = nil; | |
NSArray *command = nil; | |
NSString *documentsDir = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; | |
NSString *downloadPath = [documentsDir stringByAppendingString:[NSString stringWithFormat:@"/response.txt", [request integerForKey:@"id"]]]; | |
if ([request isKindOfClass:[NSArray class]]) | |
command = [request retain]; | |
else | |
command = [[NSArray alloc] initWithObjects:request, nil]; | |
SBJSON *json = [[SBJSON alloc] init]; | |
NSString *post = [json stringWithObject:command error:nil]; | |
[command release]; | |
[json release]; | |
postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO]; | |
postLength = [NSString stringWithFormat:@"%d", [postData length]]; | |
method = @"POST"; | |
ASIHTTPRequest *urlRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[queryParam url]]]; | |
[urlRequest addRequestHeader:@"Content-Type" value:@"application/x-json"]; | |
[urlRequest setTimeOutSeconds:20.0f]; | |
[urlRequest setRequestMethod:method]; | |
// [urlRequest setDidReceiveResponseHeadersSelector:@selector(requestDidReceiveResponseHeader:)]; | |
if (nil != postData) | |
{ | |
[urlRequest appendPostData:postData]; | |
} | |
if (nil != postLength) | |
{ | |
[urlRequest setPostLength:[postData length]]; | |
} | |
[urlRequest setUsername:[param userName]]; | |
[urlRequest setPassword:[param password]]; | |
[urlRequest setValidatesSecureCertificate:NO]; | |
[urlRequest setDelegate:self]; | |
[urlRequest setDownloadDestinationPath:downloadPath]; | |
[urlRequest setDownloadProgressDelegate:progressDelegate]; | |
[urlRequest setNumberOfTimesToRetryOnTimeout:3]; | |
[urlRequest setTemporaryFileDownloadPath:[downloadPath stringByAppendingString:@".download"]]; | |
[urlRequest setAllowResumeForFileDownloads:YES]; | |
[urlRequest setShowAccurateProgress:YES]; | |
[urlRequest setShouldPresentCredentialsBeforeChallenge:YES]; | |
[urlRequest startAsynchronous]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment