我正在尝试创建一个从api doc检索可用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方法。这真让我抓狂!我没有在其他地方使用过这个路径或方法,为什么请求错了?谢谢!
答案 0 :(得分:0)
因为你在打电话:
[[RKObjectManager sharedManager] postObject: obj ...
你应该打电话的地方:
[[RKObjectManager sharedManager] getObjectsAtPathForRouteNamed:kFindWebsockets ...