IOS AFNetworking upload pictures to the server.The request is successful,But it can not parse base64 image.Then same request using ASIHTTPReuqest framework upload base64 images on the server side can parse is successful.Can you give a suggestion or idea?
AFNworking request Code:
UIImage *img = [avatar imageWithImageSimple:avatar scaledToSize:EZSIZE(320, 320)];
NSData* imageData = UIImageJPEGRepresentation(img, 0.5);
NSString *strBase64 = [imageData base64String];
NSDictionary * object = @{
@”firstname” :@”nameTest”,
@”sex” :@”male”,
@”user_id” :@”1234556″,
@”avatar” :strBase64,
@”phone” :@”15899402939″
};
NSMutableDictionary *parameter = [[NSMutableDictionary alloc] init];
[parameter setObject:@1 forKey:@”app”];
[parameter setObject:@”save_settings” forKey:@”m_action”];
[parameter setObject:[[object JSONRepresentation] forKey:@”m_param”]];
NSURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@”POST”
URLString:@”http://test…”
parameters:parameter
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
} error:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
ASIHttpRequest request code:
UIImage *img = [avatar imageWithImageSimple:avatar scaledToSize:EZSIZE(320, 320)];
NSData* imageData = UIImageJPEGRepresentation(img, 0.5);
NSString *strBase64 = [imageData base64String];
NSDictionary * object = @{
@”firstname” :@”nameTest”,
@”sex” :@”male”,
@”user_id” :@”1234556″,
@”avatar” :strBase64,
@”phone” :@”15899402939″
};
NSString *parameter = @”app=1″;
parameter = [[parameter stringByAppendingString:@”&m_action=”] stringByAppendingString:@”save_settings”];
parameter = [[parameter stringByAppendingString:@”&m_param=”] stringByAppendingString:[object JSONRepresentation]];
NSData *data = [parameter dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
[request setDidFailSelector:@selector(handleRequestEventError:)];
[request setDidFinishSelector:@selector(parseAndSave:)];
[request addRequestHeader:@”Content-Length” value:[@([data length]) stringValue]];
[request setRequestMethod:@”POST”];
[request appendPostData:data];
[request addRequestHeader:@”Content-Type” value:@”application/x-www-form-urlencoded”];
[request setDelegate:self];
[_networkQueue addOperation:request];
40
这样有影响,假如json里套json的话,服务器拿到param后,实际上拿到的是一个字符串,需要再次把这个字符串解析为json