AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain", @"text/html", @"application/x-www-form-urlencoded",@"text/xml",@"multipart/form-data",nil];
manager.requestSerializer=[AFHTTPRequestSerializer serializer];
if (params[@"Filedata"]) {
[manager POST:urlStr parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
NSData *data = UIImagePNGRepresentation(params[@"Filedata"]);//UIImageJPEGRepresentation(params[@"Filedata"], 0.1);
NSString *name = @"image.png";
NSString *formKey = @"Filedata";
NSString *type = @"image/png";
[formData appendPartWithFileData:data name:formKey fileName:name mimeType:type];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *nameStr = [[NSString alloc]initWithData: responseObject encoding:NSUTF8StringEncoding];
NSLog(@"responseObject = %@ \n%@",responseObject,nameStr);
NSArray *resArr = [nameStr componentsSeparatedByString:@"|"];
if (resArr.count==8 && [resArr[2] isEqualToString:@"0"]) {
callback(resArr,YES);
}else{
callback(nil,NO);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error = %@",error);
}];
return;
}
网友评论