gpt4 book ai didi

c# - 有没有办法使用 Uri 类在 url 中保留点段?

转载 作者:行者123 更新时间:2023-11-30 17:36:18 25 4
gpt4 key购买 nike

当我创建带有点段的 uri 时:

var uri = new Uri("http://localhost/../../g");

uri 类删除了 ../ 段,结果 uri 变为:

http://localhost/g

当点之前有路径时:

var uri = new Uri("http://localhost/a/b/c/./../../g");
// Result: http://localhost/a/g

看起来 Uri 类在 the standart 之后(第 33 页 - remove_dot_segments),但是有什么方法可以保留点段而不是使用 Uri 自动解析目标 uri类(class)?还是我需要自定义实现?

最佳答案

如果您使用的是 HTTP,则不会,如果您使用 Uri 类,它总是会转义它们。它对以下所有内容进行转义:file、http、https、net.pipe 和 net.tcp

如果您使用的是 ftp 之类的东西,那么它不会转义,但听起来这不是您的选择。

来自 MSDN's documentation :

As part of canonicalization in the constructor for some schemes, escaped representations are compacted. The schemes for which URI will compact escaped sequences include the following: file, http, https, net.pipe, and net.tcp. For all other schemes, escaped sequences are not compacted. For example: if you percent encode the two dots ".." as "%2E%2E" then the URI constructor will compact this sequence for some schemes. For example, the following code sample shows a URI constructor for the http scheme.

关于c# - 有没有办法使用 Uri 类在 url 中保留点段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39835099/

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