服务端为新浪服务器模型 (单纯文件的存储)
方法一:
// AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://192.168.1.191:8080" ]];
// [manager.operationQueue cancelAllOperations];
// AFJSONRequestSerializer *rs = [AFJSONRequestSerializer serializer];
// manager.requestSerializer = rs;
// UIImage *image = [UIImage imageNamed:@"icon.png"];
// NSData *data = UIImageJPEGRepresentation(image, 1.0);
// NSDictionary *dic = @{@"key":@"大上海"};
// [manager POST:@"/icreate_manager/demoUpload" parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
// [formData appendPartWithFileData:data name:[NSString stringWithFormat:@"demoFile"] fileName:[NSString stringWithFormat:@"demoFileName"] mimeType:@"image/jpeg"];
// [formData appendPartWithFileData:data name:[NSString stringWithFormat:@"demoFile"] fileName:[NSString stringWithFormat:@"demoFileName"] mimeType:@"image/jpeg"];
//} success:^(AFHTTPRequestOperation *operation, NSDictionary *statusDict) {
// NSLog(@"success-------");
//} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// NSLog(@"%@",error);
//}];
方法二:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"text/plain",nil];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSDictionary *dic = @{@"key":@"大上海"};
[manager POST:@"http://192.168.1.191:8080/icreate_manager/demoUpload" parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData){
UIImage *img = [UIImage imageNamed:@"icon.png"];
NSData *data = UIImageJPEGRepresentation(img, 1.0);
// NSData *data = UIImagePNGRepresentation(img);
[formData appendPartWithFileData:data name:@"demoFile" fileName:@"demoFileName" mimeType:@"image/jpeg"];
} success:^(AFHTTPRequestOperation *operation, NSDictionary *statusDict) {
NSLog(@"oookkkk=======");
NSLog(@"%@",statusDict);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"nononono==---==");
NSLog(@"%@",error);
}];