Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios RESTKit请求后教程_Ios_Objective C_Restkit_Restkit 0.20 - Fatal编程技术网

Ios RESTKit请求后教程

Ios RESTKit请求后教程,ios,objective-c,restkit,restkit-0.20,Ios,Objective C,Restkit,Restkit 0.20,我想知道是否有关于如何使用RESTKit进行POST请求的具体教程。我看过一些教程,但没有发现任何教程说,“这正是您使用RESTKit执行POST请求的方式。”非常感谢您的帮助。假设您已经有了映射模型,您只需执行以下操作: 首先,使用响应描述符的反向映射设置请求描述符,假设您有一个映射 //This is used for mapping responses, you already should have one of this. PS:[Data mapping] is a method t

我想知道是否有关于如何使用RESTKit进行POST请求的具体教程。我看过一些教程,但没有发现任何教程说,“这正是您使用RESTKit执行POST请求的方式。”非常感谢您的帮助。

假设您已经有了映射模型,您只需执行以下操作:

首先,使用
响应描述符
的反向映射设置
请求描述符
,假设您有一个映射

//This is used for mapping responses, you already should have one of this. PS:[Data mapping] is a method that returns an RKObjectMapping for my model. You should create yours or use a previous created one
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[Data mapping] pathPattern:nil keyPath:@"data" statusCodes:statusCodeSet];
[[RKObjectManager sharedInstance] addResponseDescriptor:responseDescriptor];

//Inverse mapping, to perform a POST
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[[Data mapping] inverseMapping]  objectClass:[Data class] rootKeyPath:nil];
[[RKObjectManager sharedInstance] addRequestDescriptor:requestDescriptor];
之后,要执行POST,只需调用下面的方法。Restkit将获取您试图发布的实例,将其序列化并发送到所选路径

[[RKObjectManager sharedInstance] postObject:instanceOfYourModel path:yourPathHere parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    NSLog(@"Success");

} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    NSLog(@"Error");
}];

如果您没有映射模型,请告诉我,以便我们可以尝试其他方法。

我真的不知道映射模型是什么。是这样的:RKObjectMapping*mapping=[RKObjectMappingForClass:[Login class]];[映射addAttributeMappingsFromArray:@[@“用户名”,“密码”];回归映射;对对象映射有一个方法[mapping inverseMapping]。只需创建一个请求描述符,如图所示,并将其发送到RKObject管理器,就可以执行postObject。如果有任何疑问,请问我,我希望我能接受答案:这对我帮助很大+1.至少在我上次测试Restkit(版本0.20.0)时,
postObject:
方法使用
RKRequestDescriptor
自动序列化参数中传递的对象,并在请求正文中发送到服务器,而无需传递任何
参数,例如,如果您使用的是
AFNetwork
,您就必须这样做。很遗憾,这是不可能的。如果确实不想使用实体映射,可以使用
[RKObjectManager sharedManager].HTTPClient的
方法的
后路径:参数:成功:失败:
。有关详细信息,请参阅此方法的文档: