RestSharp - array as querystring parameter

I cannot pass an array (int array) as a query string parameter for RestSharp client

var client = new RestClient(baseUrl);
client.Authenticator = new HttpBasicAuthenticator(username, password);

var request = new RestRequest(_endpoint, Method.GET);
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("contenttype", "application/json; charset=utf-8");
            request.AddHeader("Accept", "text/html, application/xhtml+xml, image/jxr, */*");


//i tried with
request.AddParameter("messageIds", "[1,2,3]");
or
request.AddParameter("messageIds", new int[] {1,2,3} );
or
request.AddQueryParameter("messageIds", "[1,2,3]");
or
request.AddQueryParameter("messageIds", new int[] {1,2,3} );

      

Suppose the problem is with the UrlEncoding parameters

in case I pass values ​​using "new int [] {1,2,3}" (both AddParameter and AddQueryParameter) the url is constructed like this:

ResponseUri = {https://demo.xxxxxxxx.com:8181/ws/messages/zippedMessages?messageIds=System.Int32[]}

      

in case I pass the values ​​as string "[1,2,3]" (both AddParameter and AddQueryParameter), the url is constructed like this:

ResponseUri = {https://demo.xxxxxxxx.com:8181/ws/messages/zippedMessages?messageIds=[1%2C2%2C3]}

      

instead, the working url should be:

ResponseUri = {https://demo.xxxxxxxx.com:8181/ws/messages/zippedMessages?messageIds=%5B1,2,3%5D}

      

or at least:

ResponseUri = {https://demo.xxxxxxxx.com:8181/ws/messages/zippedMessages?messageIds=[1,2,3]}

      

the "AddParameter" method encodes a comma, but not [] if it is the opposite.

Is there a way to change this behavior? is there really something like a PreExecute event where characters can be moved? or some other workaround?

+3


source to share





All Articles