Restkit发送POST方法而不是GET方法



我正试图创建一个方法,从api文档中检索可用的websocket服务器。我的检索方法是:

-(void)getWebsocketServer: (GenericObject *)obj{
[[RKObjectManager sharedManager]  postObject: obj
                                  path:@"v1/ambulances/websocket_servers.json"
                                  parameters:@{
 @"auth_token" : self.accessToken,
 @"api_key" : self.api_key,
 }
                                     success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
                                         RKLogInfo(@"Update drivers complete refresh view...");
                                     }
                                     failure:^(RKObjectRequestOperation *operation, NSError *error) {
                                         RKLogError(@"Update Drivers failed with error: %@", error);
                                         [UIAlertView alertViewWithTitle:@"Cannot connect to server"
                                                                 message:[NSString stringWithFormat:@"Try again later", [error localizedDescription]]];
                                     }];
}

这里是第二部分,映射:

  RKObjectMapping *websocketMapping = [RKObjectMapping mappingForClass:[GenericObject class]];
[websocketMapping addAttributeMappingsFromArray:@[@"servers"] ];

// Routes for Users
[self.objectManager.router.routeSet addRoute:[RKRoute routeWithName:kFindWebsockets
                                                        pathPattern:@"v1/ambulances/websocket_servers.json"
                                                             method:RKRequestMethodGET]];
RKResponseDescriptor *websocketDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:websocketMapping
                                                                                 pathPattern:@"v1/ambulances/websocket_servers.json"
                                                                                     keyPath:nil
                                                                                 statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
  [self.objectManager addResponseDescriptor:websocketDescriptor];

在映射中,我显然使用了方法:RKRequestMethodGET,但当我发出请求时,charles(我的web调试器)显示了一个POST方法。这简直把我逼疯了!我在其他任何地方都没有使用过这种路径或方法,那么为什么请求是错误的呢?谢谢

因为您正在调用:

[[RKObjectManager sharedManager]  postObject: obj ...

您应该拨打的电话:

[[RKObjectManager sharedManager]  getObjectsAtPathForRouteNamed:kFindWebsockets ...

相关内容

  • 没有找到相关文章

最新更新