我有以下 C# 代码 Uri uri = new Uri("http://localhost/query?param=%E2%80%AE");
和 uri
将其解释为 http://localhost/query?param=
而不是 http://localhost/query?param=%E2%80%AE
。结果,http web 服务器得到 http://localhost/query?param=
(没有这个参数的值)。为什么它会破坏我的 url 以及如何使用我的 http://localhost/query?param=%E2%80%AE
正确创建 HttpWebRequest
?
附言我使用 System.Uri.EscapeDataString(Convert.ToString((char)8238))
获得了 %E2%80%AE
。
最佳答案
ToString()
将尝试将 uri 呈现为字符串。即,它将转义转义字符。但是,转义序列 %E2%80%AE
不可打印。
改用AbsoluteUri
。
var uriStr = uri.AbsoluteUri; // "http://localhost/query?param=%E2%80%AE"
关于c# - 为什么 System.Uri 会破坏我的网址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26533279/