奇怪的编码问题 - 希伯来语
我有一个跟踪访问和访问的脚本引用某个网站。
我将 document.referrer (我在 javascript 中使用 escape() )发送到服务器 并使用 HttpUtility.HtmlDecode (C#) 对其进行解码后,将字符串存储在数据库中。
对于大多数情况,我可以解析引用字符串并显示希伯来语字符, 但有一些情况我不能。
我发现这两个字符串是不同的(一个显示正确,一个不显示),
显示正确的字符串包含这些字符: http://www.google.co.il/search?hl=iw&source=hp&q=%D7%99%D7%91%D7% 95%D7%90%D7%A0%D7%99%D7%9D %D7%9C%D7%9E%D7%AA%D7%A0%D7%95%D7%AA &元=& ;aq=f&oq=
无法正确显示的(除非我使用 Microsoft.JScript.GlobalObject.unescape)如下所示: http://www.google.co.il/custom ?q=%FA%EE%E9%F8 - %F6%E9%E9 %F8%EB%E1&client=pub-0385896995839253&forid=1
我可以理解第二个字符串包含 ISO-8859- 1 个字符,并且在服务器端未转义时可以正常工作,但是 url 中没有编码信息
,因此我无法区分这两种格式。或者我可以吗?我应该吗?
注意:当我复制时将这些网址粘贴到浏览器地址栏中,浏览器将第一个网址检测为“Unicode(UTF-8)”,将另一个网址检测为“Windows-1255
” 亚龙
I have a script which tracks visits & referers to a website.
I send the document.referrer (I use escape() in javascript) to the server
and store the string in the database, after decoding it using HttpUtility.HtmlDecode (C#).
For most cases, I can parse the referer string and show hebrew characters,
but there are a few cases which I cannot.
I found that the two strings are different (the one displays right and the one the doesn't)
The one that displays right contains these kind of characters:
http://www.google.co.il/search?hl=iw&source=hp&q=%D7%99%D7%91%D7%95%D7%90%D7%A0%D7%99%D7%9D %D7%9C%D7%9E%D7%AA%D7%A0%D7%95%D7%AA &meta=&aq=f&oq=
The ones that doesn't display properly (unless I use Microsoft.JScript.GlobalObject.unescape) look like this:
http://www.google.co.il/custom?q=%FA%EE%E9%F8 - %F6%E9%E9 %F8%EB%E1&client=pub-0385896995839253&forid=1
I can understand that the second string contains ISO-8859-1 characters, and works properly when unescaped on the server side, but there is no encoding information as part of a url
so, I cannot distinguish between these two formats. or can I? should I?
A note: when I copy & paste those urls in the browser address bar, the browser detects the first one as "Unicode(UTF-8)" and the other one as "Windows-1255"
Thanx
Yaron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
encodeURIComponent
函数而不是escape
函数。如果您正在从 Request.QueryString 集合中读取值,则该值已被解码,因此您不应使用
HtmlDecode
方法。Use the
encodeURIComponent
function instead of theescape
function.If you are reading the value from the Request.QueryString collection it's already decoded, so you should not use the
HtmlDecode
method.