0

I am trying to add an unescaped parameter to a URL with the help of UriBuilder. How can I prevent the characters of the parameter to be escaped?

query.Set("oauth_signature", CONSUMER_SECRET + "%26");
builder.Query = query.ToString();

The resulting URL always contains % as an escaped sequence as the oauth_signature value (which is %25 apparently).

2
  • Of what type is the 'query' variable in your code snippet? Commented Jul 1, 2011 at 9:43
  • It seems to be a subclass NameValueCollection (toString() produces a correct query string). Commented Jul 1, 2011 at 10:31

2 Answers 2

1

%26 is & right? Why not just do

query.Set("oaut_signature", CONSUMER_SECRET + "&");
Sign up to request clarification or add additional context in comments.

1 Comment

Oh, well, I've previously used a simple string containing the query parameters to create a URI object and & was not being escaped; I thought I tried it using UriBuilder as well. Apparently I didn't, and your solution works as it should. Thank you very much! Sometimes one does not see the forest for the trees ;-)
0

A dirty workaround would be to use a token to identify where the parameter should go in, and string.Replace it afterwards. It's not safe though, which is probably why there's no easy way with UriBuilder.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.