C#ASP.NET HttpWebRequest自动从查询字符串中解码“&”值吗?
作者:互联网
假设以下网址:
"http://server/application1/TestFile.aspx?Library=Testing&Filename=Documents & Functions + Properties.docx&Save=true"
我使用HttpUtility.UrlEncode()对Filename参数的值进行编码,并创建以下URL:
"http://server/application1/TestFile.aspx?Library=Testing&Filename=Documents%20%26%20Functions%20%2B%20Properties.docx&Save=true"
我从客户端向C#Web应用程序发送以下(编码版本)请求.在服务器上,当我处理请求时,我遇到了问题. HttpRequest变量包含部分解码的查询字符串.也就是说,当我尝试使用或快速观察HttpRequest的以下属性时,它们具有以下值.
Property = Value
================
HttpRequest.QueryString = "{Library=Testing&Filename=Documents+&+Functions+++Properties.docx&Save=true}"
HttpRequest.Url = "{http://server/application1/TestFile.aspx?Library=Testing&Filename=Documents & Functions + Properties.docx&Save=true}"
HttpRequest.Url.AbsoluteUri = "http://server/application1/TestFile.aspx?Library=Testing&Filename=Documents%20&%20Functions%20+%20Properties.docx&Save=true"
我还检查了以下属性,但所有属性都有&值已解码.但是,所有其他值仍保持正确编码(例如space为).
HttpRequest.Url.OriginalString
HttpRequest.Url.Query
HttpRequest.Url.PathAndQuery
HttpRequest.RawUrl
我无法正确读取参数Filename的值.我想念什么吗?
解决方法:
QueryString属性返回一个NameValueCollection对象,该对象将querystring键映射到完全解码的值.
您需要编写Request.QueryString [“ FileName”].
标签:ampersand,decode,query-string,asp-net,c 来源: https://codeday.me/bug/20191023/1916052.html