加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 为什么HttpUtility.UrlEncode(HttpUtility.UrlDecode

发布时间:2020-12-15 23:43:43 所属栏目:asp.Net 来源:网络整理
导读:我有一个文件下载的问题,下载正在用下划线替换所有的空格. 基本上我在这里遇到一个问题: Response.AddHeader("Content-Disposition","attachment; filename=" + someFileName); 问题是如果someFileName中有一个空格,例如“check this out.txt”,那么用户会
我有一个文件下载的问题,下载正在用下划线替换所有的空格.

基本上我在这里遇到一个问题:

Response.AddHeader("Content-Disposition","attachment; filename=" + someFileName);

问题是如果someFileName中有一个空格,例如“check this out.txt”,那么用户会被提示下载“check_this_out.txt”.

我认为最好的选择是UrlEncode文件名,所以我试过

HttpUtility.UrlEncode(someFileName);

但它正在用加号替代空格,这使我失望了.所以我刚才试过

HttpUtility.UrlEncode(HttpUtility.UrlDecode("%20"))

并且解码工作正常并给我一个空间,但是编码占用空间,然后再次给我加号.

我在这里缺少什么,这是正确的吗?如果是这样,我应该如何正确地将空格编码成’s’,这就是我所需要的.

解决方法

报价从 this link

I’ve come across this myself. If you
are able to change the spaces to %20s
then IE7 will convert them correctly.
Firefox though will take them
literally ( at least when using the
Content-disposition header) so you
will need to do this for requests from
IE7 only.

We did the following in our app. ( a
tomcat based document repository)

06000

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读