创建开放的我们在.NET自动urlde codeS从传递的字符串的所有参数 [英] Creating an Uri in .NET automatically urldecodes all parameters from passed string

查看:132
本文介绍了创建开放的我们在.NET自动urlde codeS从传递的字符串的所有参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我要创建以下字符串的Uri对象:

Suppose I want to create an Uri object from the following string:

string url = @"http://someserver.com?param1=1&url=http%3a%2f%2fwww.otherserver.com";
Uri uri = new Uri(url, UriKind.Absolute);

预期结果将是:

Expected result would be:

http://someserver.com?param1=1&url=http%3a%2f%2fwww.otherserver.com 

获得:

http://someserver.com/?param1=1&url=http://www.otherserver.com

同样的行为注意到,在许多相关的方法,使开放的创作:Uri.TryCreate,UriBuilder.Uri等

The same behavior is noticed in many related methods that allow Uri creation: Uri.TryCreate, UriBuilder.Uri, etc.

我将如何得到一个URI,它preserve初始连接codeD参数?

How would I get an Uri that preserve initial encoded parameter?

推荐答案

此行​​为的记载

随着标准化在构造函数中的一些方案的一部分,   逃脱重新presentations被压缩。该计划为其URI将   小巧转义序列包括以下内容:文件,HTTP,HTTPS,   net.pipe和的net.tcp。对于所有其他方案,逃脱序列   不板结。例如:如果您%的EN code中的两个点..作为   %2E%2E那么URI构造函数将压缩该序列的部分   计划。例如,下面的code示例显示了一个URI   构造http方案。

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.

所以,一个解决办法可能是暂时使用自定义方案(如 leavemealone:// )来构造URL对象(可能通过 UriBuilder ?)。

So one workaround might be temporarily using a custom scheme (e.g. leavemealone://) to construct the URL objects (possibly through UriBuilder?).

这篇关于创建开放的我们在.NET自动urlde codeS从传递的字符串的所有参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆