Restkit获取使用参数与同座的客户端共享(Restkit Get with Params & B

2019-09-21 21:44发布

它不会让我附PARAMS请求,我究竟做错了什么? PARAMS是一个字典和endString增加了sharedClient基本URL。

[[RKClient sharedClient] get:endString usingBlock:^(RKRequest *loader){
    loader.params = [RKParams paramsWithDictionary:params];
    loader.onDidLoadResponse = ^(RKResponse *response) {

        [self parseJSONDictFromResponse:response];
    };


    loader.onDidFailLoadWithError = ^(NSError *error) {
        NSLog(@"error2:%@",error);
    };
}];

我得到这个错误: RestKit was asked to retransmit a new body stream for a request. Possible connection error or authentication challenge? RestKit was asked to retransmit a new body stream for a request. Possible connection error or authentication challenge?

Answer 1:

我认为你是在正确的轨道上。 下面是从一个工作示例,我发现在这里 ,大约2/3的一路下跌的页面。 为你的另一个选择可能对PARAMS直接附加到URL。 我不知道这是对你是可行的,但如果你的参数是简单的那么它可能是。

- (void)authenticateWithLogin:(NSString *)login password:(NSString *)password onLoad:(RKRequestDidLoadResponseBlock)loadBlock onFail:(RKRequestDidFailLoadWithErrorBlock)failBlock
{
    [[RKClient sharedClient] post:@"/login" usingBlock:^(RKRequest *request) {
        request.params = [NSDictionary dictionaryWithKeysAndObjects:
                          @"employee[email]", login,
                          @"employee[password]", password,
                          nil];
        request.onDidLoadResponse = ^(RKResponse *response) {

            id parsedResponse = [response parsedBody:NULL];
            NSString *token = [parsedResponse valueForKey:@"authentication_token"];
            //NSLog(@"response: [%@] %@", [parsedResponse class], parsedResponse);

            if (token.length > 0) {
                NSLog(@"response status: %d, token: %@", response.statusCode, token);
                [[RKClient sharedClient] setValue:token forHTTPHeaderField:@"X-Rabatme-Auth-Token"];

                if (loadBlock) loadBlock(response);
            }

            [self fireErrorBlock:failBlock onErrorInResponse:response];
        };
        request.onDidFailLoadWithError = failBlock;
    }];
}

你也应该看一看这太问题: RestKit GET查询参数 。



文章来源: Restkit Get with Params & Block with Shared Client