且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-08-31 11:33:10

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

If you are using HTTP then no, it will always escape them if you use the Uri class. It escapes for all of the following: file, http, https, net.pipe, and net.tcp

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

If you are using something like ftp then it won't escape, but it sounds like that isn't an option for you.

来自 MSDN 的文档:

作为某些方案的构造函数中规范化的一部分,转义的表示被压缩.URI 将用于的方案紧凑的转义序列包括以下内容:file、http、https、net.pipe 和 net.tcp.对于所有其他方案,转义序列是未压缩.例如:如果您将两个点.."百分比编码为"%2E%2E" 然后 URI 构造函数将压缩这个序列计划.例如,以下代码示例显示了一个 URIhttp 方案的构造函数.

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.