using System;
public class Test
{
public static void Main()
{
var baseUrl = new System.Uri("http://w...content-available-to-author-only...g.com");
var builder = new System.UriBuilder(baseUrl);
string name = "param";
string val = "{'blah'}";
builder.Query = name + "=" + val;
// Try several different ouput methods
Console.WriteLine(builder.ToString());
Console.WriteLine(builder.Uri.ToString());
Console.WriteLine(builder.Query);
// Shouldn't the {, }, and '}' characters be URLEncoded? I expected the
// output to be %7B%27blah%27%7D
// The System.UriBuilder.Querey docs say that
// "The query information is escaped according to RFC 2396"
// http://msdn.microsoft.com/en-us/library/system.uribuilder.query(v=vs.110).aspx
// You can test our URL encoding of these characters using a web tool like
// http://m...content-available-to-author-only...b.com/eric/tools/dencoder/
// or using JavaScript's encodeURI: http://j...content-available-to-author-only...e.net/7wgtJ/
// or using a C# class--but unfortunately both HttpServerUtility and
// WebUtility, which provide URL encoding, seem unavailable in ideone.
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewoJCXZhciBiYXNlVXJsID0gbmV3IFN5c3RlbS5VcmkoImh0dHA6Ly93Li4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5nLmNvbSIpOwoJCXZhciBidWlsZGVyID0gbmV3IFN5c3RlbS5VcmlCdWlsZGVyKGJhc2VVcmwpOwoJCXN0cmluZyBuYW1lID0gInBhcmFtIjsKCQlzdHJpbmcgdmFsID0gInsnYmxhaCd9IjsKCQlidWlsZGVyLlF1ZXJ5ID0gbmFtZSArICI9IiArIHZhbDsKCQkKCQkvLyBUcnkgc2V2ZXJhbCBkaWZmZXJlbnQgb3VwdXQgbWV0aG9kcwoJCUNvbnNvbGUuV3JpdGVMaW5lKGJ1aWxkZXIuVG9TdHJpbmcoKSk7CgkJQ29uc29sZS5Xcml0ZUxpbmUoYnVpbGRlci5VcmkuVG9TdHJpbmcoKSk7CgkJQ29uc29sZS5Xcml0ZUxpbmUoYnVpbGRlci5RdW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