我有这样的 JavaScript 代码:
function OnRequestComplete(result) {
// Download the file
//Tell browser to open file directly
alert(result);
var requestImage = "Handler.ashx?path=" + result;
document.location = requestImage;
}
Handler.ashx 代码如下:
public void ProcessRequest(HttpContext context)
{
Context = context;
string filePath = context.Request.QueryString["path"];
filePath = context.Server.MapPath(filePath);
}
在 filePath 中,我们没有任何 + 号(而是空格)。
我该如何解决这个问题?
为什么 Request.QueryString["path"] 将所有 + 号转换为空格?
最佳答案
当您正确编码查询字符串时,空格将变为 +
,而 +
将变为 %2B
。解码过程正好相反,这就是为什么你的 +
变成了空格。
问题是你没有encode查询字符串,这意味着它的解码不正确。
var requestImage = "Handler.ashx?path=" + encodeURIComponent(result);
关于c# - 为什么 Request.QueryString ["path"] 将所有 + 号转换为空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7867603/