从完成的ASIHTTPRequest获取postValue

时间:2012-06-22 09:36:32

标签: iphone objective-c ios ipad asihttprequest

我想知道如何从完成的ASIHTTPRequest中检索帖子值。

当我执行请求时,我这样做:

[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];

因为我想下载zip文件,名称就像我的书的ID。

- (void)requestFinished:(ASIHTTPRequest *)request方法中,我需要该ID来解压缩文件。我无法将ID保存在ivar中,因为我想支持多个异步下载。

我该怎么做?有没有类似于不存在的方法[request postValueForKey: key]

2 个答案:

答案 0 :(得分:7)

当您创建ASIFormDataRequest时,只需设置 userinfo 并按照这样设置即可。

设置用户信息时请使用此功能。

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

获取用户信息使用此功能。

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

答案 1 :(得分:4)

您可以使用userInfo

ASIHTTPRequest属性

如下所示

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

然后在requestFinished

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