RestRequest Parameter: string array

3,283 views
Skip to first unread message

Dustin

unread,
Mar 15, 2012, 5:59:47 PM3/15/12
to RestSharp
I need to pass a string array as a parameter. The API documentation
has a url like this:

?action=do_something&emails[]=email1&emails[]=email2

It is taking an array of emails and pass them in via the URL. However,
it would appear for this to work with RestSharp I would need to loop
the array and build the url and add parameters to the request. But, I
would like to know if there is a better way to do this.

my current RestRequests are structured like this:

public RestRequest CreateDoSomethingRequest(string name)

var request = new RestRequest(Method.GET);
request.resource = "rest?action=do_something&name={name}";
request.AddParameter("name",name,ParameterType.UrlSegment);

return request;

BUT with the array - I don't think this would work:

public RestRequest CreateDoSomethingRequest(string[] emails)

var request = new RestRequest(Method.GET);
request.resource = "rest?action=do_something&emails[]={emails}";
request.AddParameter("emails",emails,ParameterType.UrlSegment);

return request;

Cristovão Morgado

unread,
Mar 16, 2012, 4:24:53 AM3/16/12
to rest...@googlegroups.com
try this...

var request = new RestRequest(Method.GET);
request.resource = "rest"; 
request.AddParameter("action", do_something ,ParameterType.PostOrGet);  
request.AddParameter(" name ",  name ,ParameterType.PostOrGet);   


for (i=0;i<emails.count;1++)
{
request.AddParameter("emails"+i,emails[i],ParameterType.PostOrGet);  
}

more detail only if i try the API
--
Cristovao Morgado
@TheSaintr


Dustin

unread,
Mar 20, 2012, 8:29:57 AM3/20/12
to RestSharp
Thanks. I was able to get that working.

On Mar 16, 4:24 am, Cristovão Morgado <cristovao.morg...@gmail.com>
wrote:
> try this...
>
> var request = new RestRequest(Method.GET);
> request.resource = "rest";
> request.AddParameter("action", *do_something *,ParameterType.*PostOrGet*);
> request.AddParameter(" name ",  *name *,ParameterType.*PostOrGet*);
>
> for (i=0;i<emails.count;1++)
> {
> request.AddParameter("emails"+i,emails[i],ParameterType.*PostOrGet*);
Reply all
Reply to author
Forward
0 new messages