我想知道如何从完成的 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]
的东西?
最佳答案
当你创建你的 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"];
}
关于iphone - 从完成的 ASIHTTPRequest 获取 postValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11153697/