我想知道如何从完成的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]
?
答案 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"];