1

我正在尝试使用 RestKit 模拟以下请求:

curl -X GET -H "Content-Type: application/json" -H "X-User: here@there.com" -H "X-Password: imapass" -D - -k https://api.application.com/v2/auth

我正在寻找一些指导,因为我是 RestKit 的相对新手,并且这些示例没有帮助。

对于初始化,我有:

RKObjectManager *objectManager=[RKObjectManager objectManagerWithBaseURL:@"https://api.application.com/v2"];
[RKObjectManager sharedManager].serializationMIMEType = RKMIMETypeJSON;

但我不认为我想发布一个对象,所以我猜这是错误的开始......

我还尝试了以下方法:RKParams *params = [RKParams params];

// Attach the Image from Image View
NSData* user = [@"here@there.com" dataUsingEncoding:NSUTF8StringEncoding];
NSData* pass = [@"imapass"dataUsingEncoding:NSUTF8StringEncoding];

[params setData:user forParam:@"X-User"];
[params setData:pass forParam:@"X-Password"];

// Send it for processing!
NSURL *url = [NSURL URLWithString:@"https://api.application.com/v2"];

RKClient *client = [RKClient clientWithBaseURL:url];
[RKClient setSharedClient:client];

[client post:@"/auth" params:params delegate:self];

..但我得到404。

我不是在寻找任何人给我答案,但任何指导将不胜感激。

更新: 所以我设法通过使用:

NSURL *url = [NSURL URLWithString:@"https://api.application.com/v2"];

RKClient *client = [RKClient clientWithBaseURL:url];
[RKClient setSharedClient:client];
[client setValue:@"here@there.com" forHTTPHeaderField:@"X-User"];
[client setValue:@"imapass" forHTTPHeaderField:@"X-Password"];

[client get:@"/auth" delegate:self];

...现在只需将响应令牌作为 JSON 获取。

婴儿步..

4

0 回答 0