我已经看到很多这种性质的帖子,其中尾随的“/”(或缺少)会导致模式匹配失败。
然而,我的问题是没有匹配的模式。我的错误如下所示:
“没有响应描述符与加载的响应匹配。” UserInfo=0xcb8a660 {NSErrorFailingURLStringKey= http://domain.herokuapp.com/auth/identity/callback , NSLocalizedFailureReason=从 URL ' http://domain.herokuapp.com/auth/identity/callback ' 加载了 200 响应,未能匹配所有 (3) 个响应描述符:http://domain.herokuapp.com pathPattern=(null) statusCodes=200-299> 未能匹配:响应路径'/auth/identity/callback' 与路径不匹配模式“(空)”。
“不匹配路径模式'(null)'”是我认为的问题。
设置 objectmanager 和 HttpClient:
+ (void) fireUpRestkit
{
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
//base URL @"http://domain.herokuapp.com"
NSURL *baseURL = [[SCURLManager sharedInstance] baseURL];
AFHTTPClient * client = [AFHTTPClient clientWithBaseURL:baseURL];
[client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
NSAssert(objectManager, @"objectManager did not instantiate correctly");
}
我的请求如下所示:
[[RKObjectManager sharedManager] postObject:user
path:/auth/identity/callback"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
我的描述符设置如下:
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[SCUserEntity class]];
[userMapping addAttributeMappingsFromDictionary:[SCUserEntity keyMapping]];
RKRequestDescriptor * requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:userMapping.inverseMapping
objectClass:[SCUserEntity class]
rootKeyPath:nil
method:RKRequestMethodPOST];
RKResponseDescriptor * responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:userMapping
method:RKRequestMethodGET
pathPattern:nil
keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:responseDescriptor];
[objectManager addRequestDescriptor:requestDescriptor];
当请求返回时,我在执行 postRequest 时给出的模式似乎不存在,我找不到原因。我已经逐步完成了buildResponseMappingsDictionary
和随后的比赛〜方法。当发出请求时,它们都返回正确的描述符,但是当请求需要映射时,它就不起作用了。
我从服务器得到 200 OK,我看到了请求和响应主体,它们看起来是正确的。
希望有人可以帮助我发现可能明显缺失的部分:)