带引号的 WCF 服务参数

WCF service parameter with quotes

我正在尝试通过 url 传递包含引号“[”和“]”的参数。 虽然我正在对参数字符串进行编码,但我收到了与 "illegal character in the path" 相关的错误。如果我观察路径值,它不包含“[”编码!有什么建议吗?

string parameter = System.Net.WebUtility.UrlEncode("naFwi@dipSoKSws[sdoO");
var httpClient = new HttpClient(new NativeMessageHandler());
httpClient.BaseAddress = new Uri("http://127.0.0.1:8080/");
var response = await httpClient.GetAsync(string.Format("Service.svc/function/{0}", parameter));

提前致谢!

您可以将参数值作为 base64 编码字符串传递。这样你就可以非常确定你的数据没有损坏。

var bytes = System.Text.Encoding.UTF8.GetBytes(plainText);
string parameter = System.Convert.ToBase64String(bytes);