【发布时间】:2015-04-20 03:34:00
【问题描述】:
我正在尝试使用 NSURLSession 对 .ts 文件发出 POST 请求。但是,我想知道的是,有没有一种方法可以做到这一点,而无需将 .ts 文件转换为 NSData 对象,也无需在 NSDictionary 中使用它?换句话说,我可以将 .ts 文件直接上传到预期的 URL 吗?
这是我正在使用的代码:
NSURL *url = [NSURL URLWithString:@"myURL"];
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPMethod = @"POST";
//I don't want to use the following line
NSDictionary *dictionary = @{@"key1": @"value1"};
NSError *error = nil;
//I don't want to use the following line
NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary
options:kNilOptions error:&error];
if (!error) {
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request
fromData:data completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
}];
[uploadTask resume];
}
我怎样才能做到这一点?
【问题讨论】:
标签: ios objective-c nsurlsession