iphone - 从完成的 ASIHTTPRequest 获取 postValue

标签 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] 的东西?

最佳答案

当你创建你的 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/

相关文章:

iphone - 这在 ARC 中如何工作

iphone - 缩短 UIScrollView 中的触摸延迟?

ios - Xcode 6.4 Playground CPU 使用率极高

ios - 下载并打开 PDF 文件失败,出现错误未能在 ios 中找到 PDF 标题

ios - 如何检查 ScrollView 是否在底部滚动或不在 ios 中

ios - 如何在 iOS 中将 AVAudioCompressedBuffer 写入 AAC 文件?

ios - 自定义 UIButton 不会更改其图像

iphone - UIWebView 不调用 UIScrollViewDelegate 方法

iphone - 使用 CGPDFDocumentRef 显示下载的 pdf

iphone - 如何在 iphone 应用程序中实现 activesync 协议(protocol)?