以下代码:
context.Response.Write(
context.Request.Url.AbsolutePath
+ "\n" + Uri.UnescapeDataString(context.Request.Url.AbsolutePath)
+ "\n" + context.Server.UrlDecode(context.Request.Url.AbsolutePath)
+ "\n" + HttpUtility.UrlDecode(context.Request.Url.AbsolutePath)
);
输出:
/uploads/324/d7925fa2-2d3a-4cae-ba3d-e22f48cbe55c/c/1415663111_250/regenera%20hp%20-%20c%C3%B3pia%20(2).png
/uploads/324/d7925fa2-2d3a-4cae-ba3d-e22f48cbe55c/c/1415663111_250/regenera hp - cópia (2).png
/uploads/324/d7925fa2-2d3a-4cae-ba3d-e22f48cbe55c/c/1415663111_250/regenera hp - cópia (2).png
/uploads/324/d7925fa2-2d3a-4cae-ba3d-e22f48cbe55c/c/1415663111_250/regenera hp - cópia (2).png
使用this one之类的工具并输入/uploads/324/d7925fa2-2d3a-4cae-ba3d-e22f48cbe55c/c/1415663111_250/regenera%20hp%20-%20c%C3%B3pia%20(2).png
并按解码,结果如下:
/uploads/324/d7925fa2-2d3a-4cae-ba3d-e22f48cbe55c/c/1415663111_250/regenera hp - cópia (2).png
为什么我在尝试进行URL解码时未得到正确的值?
答案 0 :(得分:1)
HttpUtility.Decode
有一个重载,可让您指定编码。您需要匹配使用该重载对URL最初进行编码的编码。
在您的情况下,您似乎需要UTF8:-
var decoded = HttpUtility.UrlDecode(url, Encoding.UTF8);
答案 1 :(得分:0)