Lolloz89
Lolloz89

Reputation: 2809

Get postValue from finished ASIHTTPRequest

I'd like to know how to retrieve a post value from a finished ASIHTTPRequest.

When I perform the request I do this:

[request setPostValue:uniqueID forKey:@"bookUniqueId"];
NSFileManager *fileManager = [[NSFileManager alloc]init];
if (![fileManager fileExistsAtPath:tempDir]) {
    [fileManager createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:nil];
}
[fileManager release];

tempDir = [[tempDir stringByAppendingPathComponent:uniqueID]stringByAppendingPathExtension:@"zip"];
[request setDownloadDestinationPath:tempDir];
[request setDelegate:self];
[request startAsynchronous];

because I want to download the zip file, named like the ID of my book.

In the - (void)requestFinished:(ASIHTTPRequest *)request method I need that ID to unzip the file. I can't save the ID in an ivar because I want to support multiple asynchronous downloads.

How can I do this? Is there something similar to the inexistent method [request postValueForKey: key] ?

Upvotes: 2

Views: 599

Answers (2)

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

You can use userInfo property of ASIHTTPRequest

Like the following

request.userInfo = [[NSMutableDictionary alloc] init];
[request.userInfo setValue:yourID forKey:@"your id"];    

And then in requestFinished

- (void)requestFinished:(ASIHTTPRequest *)request
    yourid = [request userInfo] valueForKey:@"your id"];

Upvotes: 4

Mehul Mistri
Mehul Mistri

Reputation: 15147

Whenver you create your ASIFormDataRequest Just set its userinfo and get it like this.

For setting user Info use this.

[request setUserInfo:[NSDictionary dictionaryWithObject:@"YOUR_VALUE" forKey:@"YOUR_KEY"]];

For getting user Info use this.

-(void)requestFinished:(ASIHTTPRequest *)request
{
     NSDictionary *dict = [request userInfo];
     NSString *str = [dict objectForKey:@"YOUR_KEY"];
}

Upvotes: 7

Related Questions