i can't pass an array (an int array) as query string parameter to 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} );
i suppose the problem is related to the UrlEncoding of the parameters
in case i pass the values with "new int[] {1,2,3}" (both AddParameter and AddQueryParameter) the url is built in this way:
ResponseUri = {https://demo.xxxxxxxx.com:8181/ws/messages/zippedMessages?messageIds=System.Int32[]}
in case i pass the values as a string "[1,2,3]" (both AddParameter and AddQueryParameter) the url is built in this way:
ResponseUri = {https://demo.xxxxxxxx.com:8181/ws/messages/zippedMessages?messageIds=[1%2C2%2C3]}
instead a working url should it 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 the comma but not the [ ] , should it be the opposite.
is there a way to change this behaviour? does exist something like a PreExecute event where to relpace characters? or some other workaround?
messageIds=a&messageIds=b&messageIds=c
. I've not used the RESTSharp client, but is it possible to simply add messageIds multiple times? – HankypankyUri.EncodeDataString()
– Hankypanky