RestKit 0.20 — Multiple query parameters with same name?

陌路散爱 提交于 2019-12-13 03:06:58

问题


I have an iOS application making use of RestKit 0.20-rc1 for RESTful services. I'm trying to perform a GET whereby I am providing multiple query parameters with the same name to retrieve a set of objects of the same type. For example, my URL would look like:

http://mysite.com/rest/myobjects?objID=123&objID=234&objID=345

My web service is able to accept a query like this and return the appropriate objects. My RestKit code on the client looks something like this:

NSDictionary *params = ...
RKObjectManager *objMgr = [RKObjectManager sharedManager];
[objMgr getObjectsAtPath:@"/rest/myobjects" parameters:params success:nil failure:nil];

My problem, is that the parameters must be specified as an NSDictionary, and I have multiple parameters with the same name. I tried setting the value in the NSDictionary to an NSArray containing all of the parameter values, but that did not work.

How do I specify multiple query parameters with the same name in RestKit using this methodology? Is this just not supported in RestKit?


回答1:


Sounds like it is not going to be possible with the RestKit code you have. You may either:

  1. Change the code to allow NSArrays. RestKit is open source at https://github.com/RestKit
  2. Ask on the RestKit google group to see how others have worked around this. https://groups.google.com/forum/?fromgroups#!forum/restkit
  3. Submit a patch to RestKit and wait for a release that supports what you are asking for.



回答2:


You can put the query with the parameters in the getObjectAtPath. Meaning create a string with the parameters like this:

NSString *queryPath = @"getNames?names=bob&names=joe&names=joey";

and then do this (notice that the parameters object here is nil):

[[RKObjectManager sharedManager] getObjectsAtPath:queryPath
                                           parameters:nil
                                              success:nil failure:nil];

if you have a problem with the encoding just do this: queryPath = [queryPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];



来源:https://stackoverflow.com/questions/15210694/restkit-0-20-multiple-query-parameters-with-same-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!