繁体   English   中英

为什么Request.QueryString [“ path”]会将所有+符号转换为空格?

[英]Why does Request.QueryString[“path”] converts all + signs to spaces?

我有这样的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 解码的过程相反,这就是为什么+变成空格。

问题是您没有查询字符串进行编码 ,这意味着它被错误地解码。

var requestImage = "Handler.ashx?path=" + encodeURIComponent(result);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM