URL 解码未按预期工作

发布于 2024-09-28 10:49:11 字数 630 浏览 6 评论 0原文

我的浏览器显示文件名为

http://www.example.com/pdf/204177_20090604_Chloorhexidine_DCB_oogdruppels_0%2C1%25.pdf

实际文件名为 204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf

urldecode 后,它给出错误的文件名 <代码> http://www.example.com/pdf/204177_20090604_Chloorhexidine_DCB_oogdruppels_0,1%.pdf

更新

最初我以为是 URL 解码的问题,但是像名称 204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1,2%.pdf 这样的文件在浏览器中渲染时会抛出错误请求。我正在使用 Kohana 3 框架。和服务器有关系吗?

My Browser shows URL with file name as

http://www.example.com/pdf/204177_20090604_Chloorhexidine_DCB_oogdruppels_0%2C1%25.pdf

Actual File name is 204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf

After urldecode, it gives wrong file name as

http://www.example.com/pdf/204177_20090604_Chloorhexidine_DCB_oogdruppels_0,1%.pdf

Update:

Initially I thought that its problem of URL Decode, but files like name 204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1,2%.pdf while rendering in browser throws Bad request. I am using Kohana 3 framwork. Is it related with server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心不设防 2024-10-05 10:49:11
$url = 'http://204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf';
$encode = urlencode($url);
$decode = urldecode($encode);

echo $url."<br />";
echo $encode."<br />";
echo $decode."<br />";

// outputs
http://204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf
http%3A%2F%2F204160_20090604_Atropine_DCB_oogdruppels_0%2C5%25.pdf
http://204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf

一切都好。你的错误在其他地方。

$url = 'http://204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf';
$encode = urlencode($url);
$decode = urldecode($encode);

echo $url."<br />";
echo $encode."<br />";
echo $decode."<br />";

// outputs
http://204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf
http%3A%2F%2F204160_20090604_Atropine_DCB_oogdruppels_0%2C5%25.pdf
http://204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf

All ok. You're error is somewhere else.

蝶舞 2024-10-05 10:49:11

您正在查看两个不同的文件。

无法将 204160_20090604_Atropine_DCB_oogdruppels_ 编码为 204177_20090604_Chloorhexidine_DCB_oogdruppels_,编码不会更改字母字符。

该错误很可能出现在创建文件列表并输出链接的代码中;链接标题和文件名之间的映射似乎很混乱。

You are looking at two different files.

It's not possible to urlencode 204160_20090604_Atropine_DCB_oogdruppels_ into 204177_20090604_Chloorhexidine_DCB_oogdruppels_, encoding does not change alphabetical characters.

The error is most likely in the code that creates the file list and outputs the links; the mapping between link titles and filenames appears to be messed up.

提笔落墨 2024-10-05 10:49:11

这将为您使用 c# 提供准确的文件名 m

Server.UrlDecode("http://www.example.com/pdf/204160_20090604_Atropine_DCB_oogdruppels_0,5%25.pdf")

, (逗号) 编码为 %2c
如果您使用 Request.Url ,%(百分比)会被浏览器编码为 %25,

它将解码 ,(逗号),但不会解码 %(百分比),

因此 Server.UrlDecode("xyz") 会解码所有字符除了%(百分比),那就是上面的文件名中有“%25”

this will give you exact file name m using c#

Server.UrlDecode("http://www.example.com/pdf/204160_20090604_Atropine_DCB_oogdruppels_0,5%25.pdf")

, (comma) is encoded as %2c
% (percent) is encoded as %25 by browsers

if you use Request.Url it'll decode ,(comma) but not %(percent)

So Server.UrlDecode("xyz") decode all characters except %(percent), thats y there's "%25" in the above filename

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文