假定以下網址:C#ASP.NET HttpWebRequest自動解析查詢字符串的&符號(&)值?
"http://server/application1/TestFile.aspx?Library=Testing&Filename=Documents & Functions + Properties.docx&Save=true"
我使用HttpUtility.UrlEncode()來編碼文件名參數的值和創建下面的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"
我也檢查了以下屬性,但它們都已經解碼了&值。但是所有其他值仍然是正確編碼的(例如,空格爲%20)。
HttpRequest.Url.OriginalString
HttpRequest.Url.Query
HttpRequest.Url.PathAndQuery
HttpRequest.RawUrl
我無法正確讀取參數Filename的值。我錯過了什麼嗎?
感謝您的答案,但這並不奏效。 – Ioannis 2010-09-08 13:14:16
它返回:文件(價值之後&丟失) – Ioannis 2010-09-08 13:14:57