.net 3.5 HttpRequest 请求的url 网址 如何实现不转义

来源:互联网 发布:c语言编程案例 编辑:程序博客网 时间:2024/06/14 08:31

大家一般都会使用HttpWebRequest.Create(string)这种方式,这样默认都会被转义

如果要使URL不被转义,则使用uil 创建httpWebRequest 实例即可,本人经抓包实践过。如下方式:

httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(url,true));

Uri对应构成函数说明如下:

//        // 摘要:        //     用指定的 URI 初始化 System.Uri 类的新实例,并对字符转义进行显式控制。        //        // 参数:        //   uriString:        //     一个 URI。        //        //   dontEscape:        //     如果 uriString 已完全转义,则为 true;否则为 false。请参见“备注”。        //        // 异常:        //   System.ArgumentNullException:        //     uriString 为 null。        //        //   System.UriFormatException:        //     uriString 为空或只包含空格。 - 或 - 在 uriString 中指定的方案无效。 - 或 - uriString 包含太多斜杠。 -        //     或 - uriString 中指定的密码无效。 - 或 - uriString 中指定的主机名无效。 - 或 - uriString 中指定的文件名无效。        //     - 或 - uriString 中指定的用户名无效。 - 或 - uriString 中指定的主机名或证书颁发机构名不能以反斜杠结尾。 - 或 -        //     uriString 中指定的端口号无效或无法分析。 - 或 - uriString 的长度超过 65534 个字符。 - 或 - uriString        //     中指定的方案的长度超过 1023 个字符。 - 或 - uriString 中存在无效的字符序列。 - 或 - uriString 中指定的 MS-DOS        //     路径必须以 c:\\ 开头。        [Obsolete("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")]        public Uri(string uriString, bool dontEscape);


0 0
原创粉丝点击