我正在尝试使用 AFNetworking 3 将 wav 文件作为 NSData 发送到休息服务。我想出了如何使用 AFMultipartFromData 发送,但我遇到了这样的错误
errorMessage = "Can Not Map Content-Type String multipart/form-data; boundary=Boundary+02588C5 To Media Type ";
当我与创建休息服务的人交谈时,他告诉我我必须只发送 NSData 而不是像 AFMultipartFormData 这样的东西。我在这里需要一些帮助,因为我找不到任何方法来发送“只是”NSData。我的代码如下;
NSURL *URL = [NSURL URLWithString:@"http://xxxMyService"];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.HTTPAdditionalHeaders = @{@"xx": @"yy ; zz"};
AFHTTPSessionManager *manager2 = [[AFHTTPSessionManager alloc] initWithBaseURL:URL sessionConfiguration:configuration];
manager2.responseSerializer = [AFJSONResponseSerializer serializer];
//I converted wav file to NSData
NSData *data=[self setVoiceRecordToNSData];
[manager2 POST:@"http://xxxMyService" parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
{
[formData appendPartWithFileData:data name:@"data" fileName:@"Path.wav" mimeType:@"audio/wav"];
}
progress:nil success:^(NSURLSessionTask *task, id responseObject
{ NSLog(@"JSON: %@", responseObject);}
failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error); }];