Restkit Get with Params&与共享客户端屏蔽 [英] Restkit Get with Params & Block with Shared Client

查看:78
本文介绍了Restkit Get with Params&与共享客户端屏蔽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不会让我将参数附加到请求中,我在做什么错? Params是一个Dictionary,并且endString添加到sharedClient baseURL.

It won't let me attached the params to the request, what am I doing wrong? Params is a Dictionary and endString adds to the sharedClient baseURL.

[[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?

推荐答案

我认为您的做法正确.以下是一个有效的示例,我在此处中找到有关在页面下方2/3.您的另一个选择可能是将参数直接附加到URL.我不确定这对您是否可行,但是如果您的参数很简单,那么可能就可以.

I think you are on the right track. Below is from a working example I found here, about 2/3 the way down the page. Another option for you may be to append the params directly to the URL. I'm not sure if that's feasible for you, but if your parameters are simple then it may be.

- (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;
    }];
}

您还应该查看以下SO问题: RestKit GET查询参数.

You should also take a look at this SO question: RestKit GET query parameters.

这篇关于Restkit Get with Params&与共享客户端屏蔽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆