0

我正在尝试创建一种从 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,但是当我发出请求时,查尔斯(我的网络调试器)显示了一个 POST 方法。这真让我抓狂!我没有在其他任何地方使用过此路径或方法,那么为什么请求错误?谢谢!

4

1 回答 1

0

因为你在打电话:

[[RKObjectManager sharedManager]  postObject: obj ...

你应该在哪里打电话:

[[RKObjectManager sharedManager]  getObjectsAtPathForRouteNamed:kFindWebsockets ...
于 2013-06-27T18:53:07.803 回答