- (void)requestAFHttpPost {
UIImage *postData = [UIImage imageNamed:@"lunch2.png"];
NSData *data = UIImageJPEGRepresentation(postData, 0.5);
NSString *postUrl=[@"https://ssl.ufxin.com/baseapi/appupload.php?key=youfangxin&version=2.3.10&platform=ios&userid=1332&action=house_pic&client=user&from=1" stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSString *msgLength = [NSString stringWithFormat:@"%lu", data.length];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"multipart/form-data", @"text/html", @"image/jpeg", @"application/octet-stream", @"text/xml", nil];
[manager.requestSerializer setValue:msgLength forHTTPHeaderField:@"Content-Length"];
[manager POST:postUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
// set time formate
[formatter setDateFormat:@"yyyyMMddHHmmss"];
NSString *dateString = [formatter stringFromDate:[NSDate date]];
NSString *fileName = [NSString stringWithFormat:@"%@.jpeg", dateString];
[formData appendPartWithFileData:data name:@"file" fileName:fileName mimeType:@"image/*"];
} progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
UFLog(@"success");
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
UFLog(@"failure");
}];}
使用AFNetworking3.0上傳圖像總是失敗(沒有錯誤),但我可以上傳圖片成功,同時使用郵遞員AFNetworking3.0上傳圖片總是失敗(不出錯)
請檢查我的答案在這篇文章https://stackoverflow.com/questions/41233839/afnetworking-3-0-multipart-form-data-for-uploading-image-error/41241165#41241165 –
這個失敗太 –
任何人都幫助我?該方法給我所有的回調失敗 –