我想将URL正文中的JSON 数据从我的 IOS 应用程序发送到服务器。我搜索了很多 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);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"error: %@", error);
}];
我得到了错误。我想在 URL Body 中传递这样的 JSON 数据
{"login_provider": "IOS","email": "%@","password": ”%@“,”ios_device_id": "1"}