Tag: afnetworking 3

AFNetworking v3.1.0 multipartFormRequestWithMethod上传带引号的JSON数值

当我使用AFNetworking v3.1.0 multipartFormRequestWithMethod上传文件并包含一个参数字典,该参数字典被转换为JSON,并且字典中有一个条目如: ["Test": 1] 也就是说,一个带有数值的键,当它到达我的服务器时,JSON结构是一个带引号的string。 例如: {"Test":"1"} 这不是我想要的。 我想在服务器上收到的是: {"Test": 1} 请注意,当使用AFHTTPSessionManager的POST方法(我认为不允许file upload)时,我不会遇到这个问题。 这是AFNetworking中的一个错误吗? 我在做什么? 有没有解决方法或其他解决scheme? 我已经在AFNetworking JSON序列化问题上看到了这个讨论,但是我的应用程序并不适合在服务器上进行parsing,以便按照我喜欢的方式(数字不带引号)进行parsing。 思考? 这是我使用AFNetworking的客户端代码: import Foundation import SMCoreLib // some common library functions I use class Server { private let manager: AFHTTPSessionManager! internal static let session = Server() var uploadTask:NSURLSessionUploadTask? private init() { self.manager = AFHTTPSessionManager() // https://stackoverflow.com/questions/26604911/afnetworking-2-0-parameter-encoding […]

使用AFNetworking 3.0在URL正文中发送JSON数据

我想从我的IOS应用程序发送到我的IOS应用程序的URL 身体的 JSON数据 。我search了许多SO问题,但我找不到我想要的。 如果有人知道如何处理AFNetworking然后请让我知道。谢谢这是我的代码剪发送参数 NSMutableDictionary *parameters = [[NSMutableDictionary alloc]init]; [parameters setValue:@"PY" forKey:@"AppSecret"]; [parameters setValue:@"IOS" forKey:@"login_provider"]; [parameters setValue:_txtemail.text forKey:@"email"]; [parameters setValue:_txtpassword.text forKey:@"password"]; [parameters setValue:@"1" forKey:@"ios_device_id"]; AFHTTPSessionManager *managertwo = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; managertwo.requestSerializer = [AFJSONRequestSerializer serializer]; [managertwo.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [managertwo POST:[NSString stringWithFormat:@"http://capemedics.co.za/Api/user_register/valid_user"] parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSLog(@"success! %@",responseObject); NSLog(@"%@",parameters); } […]

在AFNetwoking 3.0中上传Zip文件

我正在使用AFNetworking 3.0上传服务器上的Zip文件,但它从服务器提供以下错误。 码 AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://www,baseurl.com”]]; [manager.requestSerializer setValue:@“headertoeknvalue” forHTTPHeaderField:@"Authorization"]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"]; [ manager POST:@"sync.php" parameters:dictPost constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) { NSData *data = [[NSFileManager defaultManager] contentsAtPath:[APP_DELEGATE.strDocumentDirectoryPath stringByAppendingString:@"/Database.zip"]]; [formData appendPartWithFileData:data name:@"sync_file" fileName:@"Database.zip" mimeType:@"application/json"]; } progress:^(NSProgress * _Nonnull uploadProgress) { } success:^(NSURLSessionDataTask * _Nonnull […]

如果位置更改或不使用AFN 3,如何定期向服务器发送背景位置?

我在iOS应用程序开发中是非常新的。我将使用AFNetworking 3.0。我想在后台更新位置并将其发送到服务器。 而发送到服务器,我想条件:1)如果位置不改变,我想调用服务sendlocation1 2)如果位置更改我想调用服务sendlocation2。 位置变化(约50米)。 请帮助我….我试着下面的代码—-在ViewDidLoad: (void)viewDidLoad { [super viewDidLoad]; locationManager = [[CLLocationManager alloc] init]; locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locationManager startUpdatingLocation]; [locationManager requestAlwaysAuthorization]; float Lat = locationManager.location.coordinate.latitude; float Long = locationManager.location.coordinate.longitude; NSLog(@"Lat : %f Long : %f",Lat,Long);} 我要检查,如果我从服务器得到响应login成功,然后只发送位置到服务器,这就是为什么我使用if-else语句如下: if ([_str isEqualToString:@"Login Success"]) { UIAlertController *Loginalert= [UIAlertController alertControllerWithTitle:@"Login Success" message:@"This app is going to […]

AFNetworking 3.0用于上传图像错误的多部分表单数据

我一直在尝试使用multipart表单数据networking3.0将图像上传到我的AWS服务器,但显然,我试图上传的每个图像都以失败模块结束。 代码写在objective-c中。 – (NSURLSessionUploadTask *)uploadImageTask:(NSMutableDictionary *)dictionary { NSString *s3BucketUrl = [dictionary objectForKey:@"s3BucketUrl"]; NSData *imageData = [dictionary objectForKey:@"imageData"]; NSString *contentType = [dictionary objectForKey:@"contentType"]; NSString *filename = [dictionary objectForKey:@"filename"]; NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:s3BucketUrl parameters:dictionary constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFileData:imageData name:@"file" fileName:filename mimeType:contentType]; } error:nil]; AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; NSURLSessionUploadTask *uploadTask = […]

为多个文件下载添加子进度

我在我的项目中使用AFNetworking 3.0下载多个文件。 我想显示所有文件的单一下载进度。 我将每个文件下载的每个subprocess添加到父进程。 但它不工作,应用程序崩溃。 我收到错误 – Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<DownloadManager: 0x7f92e2f6e130>: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled. Key path: fractionCompleted 这是我的下载类 – @interface DownloadManager () @property (nonatomic, strong) NSProgress *progress; @property (nonatomic, strong) Settings *settings; @property (nonatomic, strong) DocumentDirectory *documentDirectory; @end @implementation DownloadManager – (instancetype)init { self […]

AFNetworking 3.0数据无法被读取,因为它的格式不正确

还有其他类似的题目,但没有一个帮助我。 我要发送一个PUT请求到服务器为了改变约会的状态,所以我做了这个方法-(void)appointmentStatusChangedTo:(NSString *)statusID atAppointmentID:(NSString *)appointmentID在其中我设置url和参数为 NSString *string = [NSString stringWithFormat:@"%@/API/Appointments/3",BaseURLString]; NSDictionary *para = @{ @"AppointmentStatusId":statusID, @"ID":appointmentID }; 然后我做了URL请求 AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"PUT" URLString:string parameters:para error:nil]; 之后,我将授权令牌的标头设置为 NSString *token = [NSString stringWithFormat:@"Bearer %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"userToken"]]; [req setValue:token forHTTPHeaderField:@"Authorization"]; 所以最后我把它称为 [[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable […]