RestKit在进行调用时删除路径

时间:2013-03-13 20:50:52

标签: objective-c cocoa restkit

为什么RestKit在进行API调用时会删除我的路径?它表明在通话之前它是好的。

这就是我注册的方式

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:[[NSUserDefaults standardUserDefaults] objectForKey:@"apiURL"]]];
[client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];
[client setParameterEncoding:AFJSONParameterEncoding];
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
NSLog(@"Created client: %@", objectManager.HTTPClient);

我在其他课程中称之为

RKObjectManager *manager = [RKObjectManager sharedManager];
NSLog(@"HTTP Client: %@", manager.HTTPClient);

即使在我调用共享对象管理器的其他类中,它也是正确的,但是我在调​​用期间记录日志并且响应错误,因为/api/v1被取出。

的NSLog

2013-03-13 13:24:08.960 Project[54631:403] HTTP Client: <AFHTTPClient: 0x1033d6230, baseURL: https://my.server.com/api/v1/, defaultHeaders: {
    Accept = "application/json";
    "Accept-Language" = "en, ja, fr, de, es, it, pt, pt-PT, nl, sv, nb, da, fi, ru, pl, zh-Hans, zh-Hant, ko, ar, cs, hu, tr, en-us;q=0.8";
    Authorization = "Bearer <My Access Token>";
    "User-Agent" = "Project/1.0 (Mac OS X Version 10.7.5 (Build 11G63))";
}, registeredOperationClasses: (
), operationQueue: <NSOperationQueue: 0x1033db8c0>{name = 'NSOperationQueue 0x1033db8c0'}>
2013-03-13 13:24:08.960 Project[54631:403] Manager: <RKObjectManager: 0x1033db940>
2013-03-13 13:24:08.971 Project[54631:403] I restkit.network:RKHTTPRequestOperation.m:154 GET 'https://my.server.com/features/1234?with_lock=false'
2013-03-13 13:24:09.310 Project[54631:403] I restkit.network:RKHTTPRequestOperation.m:185 GET 'https://my.server.com/features/1234?with_lock=false' (200 OK)

2 个答案:

答案 0 :(得分:1)

你有没有设置一个baseUrl到RESTKIt - 实例? 你做了一个

[[RKObjectManager alloc] initWithHTTPClient:client]

新实例。

但后来你打电话给

[RKObjectManager sharedManager]

首先尝试初始化共享的RKobject,例如:     [RKObjectManager objectManagerWithBaseURL:... 而不是使用共享实例来创建新的AFHTTPClient对象。

答案 1 :(得分:1)

你可以像这样设置它,它对我有用:

static NSString *BASE_URL = @"http://www.yourdomain.com/api/v2";
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:BASE_URL]];
[objectManager postObject:rating path:@"ratings" parameters:nil success:nil failure:nil];

问题在于我,我提供了绝对的路径:例如@&#34; /评分&#34;而不是@&#34;评级&#34;。