0

我正在尝试使用以下格式发送 PUT 请求:

http://server.com/api/tag/:tagId?extra1=abc&extra2=def

 RKObjectManager *manager = [RKObjectManager managerWithBaseURL:@"http://server.com"];

 [manager.router.routeSet addRoute:[RKRoute routeWithClass:[Tag class] pathPattern:@"/api/tag/:tagId" method:RKRequestMethodPut]];

Tag *tag = [[Tag alloc] initWithName:name andId:tagId];
[manager putObject:tag path:nil parameters:@{@"extra1":@"abc", @"extra2":@"def"}
           success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
               [delegate onRequestSuccess:request withData:tag];
           }
           failure:^(RKObjectRequestOperation *operation, NSError *error) {
           }];

[delegate onRequestStart:request];

但是参数会被放入请求的正文中,而不是像在 GET 或 DELETE 请求中那样放入 URL。POST 请求也是如此。

感谢您的任何建议。

4

1 回答 1

0

以下是我过去解决此问题的方法:

无需创建路由,只需手动创建 URL 路径,将参数直接输入字符串:

NSString *urlPath = [NSString stringWithFormat:
                      @"/api/tag/:tagId?extra1=%@&extra2=%@", @"abc", @"def"];

然后,使用而不是调用您的putObject请求:pathparameters

[manager putObject:tag path:urlPath parameters:nil
           success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
               [delegate onRequestSuccess:request withData:tag];
           }
           failure:nil];

我不确定这是否是“正确”的做法,但它绝对适合你!

于 2013-08-01T13:11:52.943 回答