user8147504
user8147504

Reputation:

How to not encode RestSharp parameter

I need to pass one of parameters to HttpRequest (POST).

Lets say we have 'someParam' parameter and we need to pass 'some+value' value.

When using request.AddParameter("someParam", "some+value"); - value is automatically converted to 'some%2Bvalue' and in request it looks like 'someparam=some%2Bvalue'. But the application only understands +.

Is there any way how to add parameter to request but don't encode it???

Upvotes: 1

Views: 2054

Answers (2)

Max Becerra
Max Becerra

Reputation: 486

You can use:

System.Web.HttpUtility.UrlDecode

for example:

var url = getUrlFromConfig();
var params = HttpUtility.UrlDecode("$foo/bar?someParam={some}&someParamValue={value}");
var client = new RestClient(apiUrl + params);

This will generate a valid url without your problem.

Upvotes: 0

S_D
S_D

Reputation: 236

On server side should be 'some%2Bvalue' decoded to "some+value". If it is not, better solution for you is to separate values to:

request.AddParameter("someParam", "some");
request.AddParameter("someParamValue", "value");

And on server side just parse parameters to some+value as you wanted.

Another workaround would be to replace string "%2" with "+". But still it is better approach to separate values.

Possible workaround for GET:

    string resource = "something";
    var client = new RestClient(baseurl+ resource +"?"+"someParam"+"="+"some+value");
    var request = new RestRequest(resource, method);
    IRestResponse<T> response = client.Execute<T>(request);
    return response.Data;

So you have to compose url by yourself and provide it whole to request.

Upvotes: 1

Related Questions