我正在使用此代码将文件上传到服务器,在服务器上未检测到流,问题是我使用相同的代码但在不同的项目中,它完美地工作!我已经包含了适当的标题!到底是怎么回事 ?我花了最后几个小时来解决这个问题,请帮忙
-(void)upload
{
NSString *st = [[NSBundle mainBundle] pathForResource:@"R" ofType:@"caf"];
NSData *d = [NSData dataWithContentsOfFile:st];
AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://192.168.0.116:8084/RasaylServer/"]];
NSString *action = @"SendStreamMessage";
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setObject:@"209" forKey:@"param1"];
[parameters setObject:@"205" forKey:@"param2"];
[parameters setObject:@"01/12/2012 15:13" forKey:@"param3"];
NSMutableURLRequest *myRequest = [client multipartFormRequestWithMethod:@"POST" path:action parameters:parameters constructingBodyWithBlock: ^(id <AFMultipartFormData>formData)
{
[formData appendPartWithFileData:d name:@"a" fileName:@"Test2" mimeType:@"audio/x-caf"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:myRequest];
[operation setCompletionBlock:^(){
} ];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:operation];
[operation start];
operation.completionBlock = ^{
if ( operation.error == nil )
NSLog(@"%@", operation.responseString);
else {
NSLog(@"%@", operation.error);
}
};
}