gpt4 book ai didi

c# - 为什么 System.Uri 会破坏我的网址?

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:08:31 25 4
gpt4 key购买 nike

我有以下 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com