Using escape for slash character - "%2f" as URL segment

1,487 views
Skip to first unread message

milan.gornik

unread,
Aug 10, 2012, 1:29:50 PM8/10/12
to rest...@googlegroups.com
Hi,

I'm using RestSharp to access RabbitMQ server. RabbitMQ uses slash character for the name of default vhost. When making some requests to RabbitMQ this name has to be included in URL of the request. However, in actual request, RabbitMQ expects this character to be written as URL-encoded sequence "%2f". If it is passed as slash character "/", the request will fail. Now, when I use code like this:

var request = new RestRequest("api/exchanges/%2f/SampleName"Method.PUT);

RestSharp will change "%2f" to "/" before executing the request (I'm checking the actual request in Fiddler).

If I do following instead:

var request = new RestRequest("api/exchanges/{vpath}/SampleName", Method.PUT);
request.AddUrlSegment("vpath", "%2f");

RestSharp will change "%2f" to "%252f" before executing the request. 

Is there a way for RestSharp to leave the character group "%2f" intact in the request URL?

I tried the workaround I saw in another discussion and which seemed related. I used blank string for Request URL and instead put the whole URL as string in BaseUrl property of the RestClient. However, that seems to behave the same. "%2f" gets automatically replaced by "/" before executing the request. Any chance I can avoid this?

Thanks!

Milan Gornik


John Sheehan

unread,
Aug 14, 2012, 5:57:27 PM8/14/12
to rest...@googlegroups.com
Did you try

var request = new RestRequest("api/exchanges/{vpath}/SampleName", Method.PUT);
request.AddUrlSegment("vpath", "/");

JT

unread,
Aug 15, 2013, 12:40:24 PM8/15/13
to rest...@googlegroups.com
Did you ever find a solution to this? 

I'm also trying to use the RabbitMQ API too and  I'm unable to create a RestRequest that passes the slash as %2f.

 If I double-encode it, it is left as %252f, if I single encode it, RestSharp converts the %25 back to a / which RabbitMQ won't accept.

Pankaj Bhanushali

unread,
Jan 28, 2019, 1:38:51 AM1/28/19
to RestSharp
Did anyone found solution for this?
Reply all
Reply to author
Forward
0 new messages