为什么HttpUtility.UrlEn code的回报,而不是+ 20%(HttpUtility.UrlDe code(QUOT;);%20&QUOT)? [英] Why does HttpUtility.UrlEncode(HttpUtility.UrlDecode("%20")) return + instead of %20?
问题描述
我在与那里的下载与下划线替代所有空格的文件下载的问题。
基本上我在这里得到了一个问题:
Response.AddHeader(内容处置,
附件;文件名=+ someFileName);
问题是,如果有someFileName它的空间,如检查这个out.txt,那么用户将被提示下载check_this_out.txt。
我想最好的办法是UrlEn code中的文件名,所以我尝试
HttpUtility.UrlEn code(someFileName);
但它用加号,这难倒我更换的空间。于是我刚试过
HttpUtility.UrlEn code(HttpUtility.UrlDe code(%20))
和去code正常工作,并给了我一个空间,但EN code占用空间,然后再次给我加号。
我缺少的是在这里,这是正确的?如果是这样,我应该如何正确连接code位到20%的,这正是我所需要的。
从<一个报价href=\"http://social.msdn.microsoft.com/forums/en-US/iewebdevelopment/thread/cc3adbf7-2e77-4eea-92ee-53065dfc19cf/\"相对=nofollow>此链接
我遇到这个自己。如果你
能够空格更改为%20秒
那么IE7将它们正确转换。
火狐虽然会带他们
字面上(至少当使用
内容处置头),所以你
需要从要求这样做
只有IE7。
我们的确在我们的应用程序如下。 ( 一个
基于Tomcat文档库)字符串的userAgent = request.getHeader(用户代理);
如果(userAgent.contains(MSIE 7.0)){
文件名= filename.replace(,%20);
}
response.addHeader(内容处置,
附件;文件名= \\+文件名+\\);
块引用>I'm having a problem with a file download where the download is replacing all the spaces with underscores.
Basically I'm getting a problem here:
Response.AddHeader("Content-Disposition", "attachment; filename=" + someFileName);
The problem is that if someFileName had a space in it such as "check this out.txt" then the user would be prompted to download "check_this_out.txt".
I figured the best option would be to UrlEncode the filename so I tried
HttpUtility.UrlEncode(someFileName);
But it's replacing the spaces with plus signs, which stumped me. So then I just tried
HttpUtility.UrlEncode(HttpUtility.UrlDecode("%20"))
and the decode works properly and gives me a space, but the encode takes the space and then gives me the plus sign again.
What am I missing here, is this correct? If so, how should I properly encode spaces into %20's, which is what I need.
解决方案Quoting from 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)
String userAgent = request.getHeader("User-Agent"); if (userAgent.contains("MSIE 7.0")) { filename = filename.replace(" ", "%20"); } response.addHeader("Content-disposition", "attachment;filename=\"" + filename + "\"");
这篇关于为什么HttpUtility.UrlEn code的回报,而不是+ 20%(HttpUtility.UrlDe code(QUOT;);%20&QUOT)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!