(就问题而言,这确实是一个双重打击,因为确实有两个独立的问题,但它们有点属于一起。)
第一个问题:
我将如何使用 POST 上传文件(我已经有一个包含文件内容的 NSData 对象),同时在NSProgressIndicator
? 很像可以做 bytesReceived in NSURLDownload
,但这次使用 POST 跟踪已经发送了多少字节。
第二个问题:
虽然我有这个NSData
数组,但我将使用下面的代码来发送NSData
数组。在这里,它让我感到困惑,例如,POST 值“文件”是NSData
对象。NSDictionary
可能会在这里完成这项工作,但我现在无法访问我的电脑和可爱的 Apple Docs。:
NSMutableURLRequest* post = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:@"http://yourdomain.com/post.php"]];
[post setHTTPMethod: @"POST"];
[post setHTTPBody:myFileNSData];
NSURLResponse* response;
NSError* error;
NSData* result = [NSURLConnection sendSynchronousRequest:post returningResponse:&response error:&error];
NSLog(@"%@", [[[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding] autorelease]);
我会很感激任何帮助。