IE 发送 ? HTTP GET 中的字符而不是 Unicode 字符
我在我的一个项目中创建了一个用于搜索操作的 Web 表单,并且 HTML 非常简单:
<form action='/search' method="post">
<input type="text" id='search-term' name='search-term' />
<input type="submit" id='start-search' alt='' value="" />
</form>
URL 将 HTTP Get 请求发送到服务器:
http://www.example.com/search?search-term=مثال
因此,当用户键入 Unicode 搜索词并按 Enter 键时,将使用以下 ,在服务器中将是:
http://www.example.com/search?search-term=%D9%85%D8%AB%D8%A7%D9%84
并且我可以使用检索 search-term
查询字符串的解码值HttpContext.Current.Server.UrlDecode("%D9%85%D8%AB%D8%A7%D9%84")
,它返回 МЫא
给我。到这里一切正常,我没有问题。
但是,如果有人直接在 IE9 中输入上述地址,然后按 Enter,那么我在服务器上得到的是:
http://www.example.com/search?search-term=????
这里出了什么问题?
更新:我们通过Fiddler检查了流量,您可以在下图中看到结果:
HTTP Get headers,由Fiddler捕获,用Firefox请求
HTTP 获取标头,由 Fiddler 捕获,通过 IE 请求
I've created a web form for search operation in one of my projects, and the HTML is pretty simple:
<form action='/search' method="post">
<input type="text" id='search-term' name='search-term' />
<input type="submit" id='start-search' alt='' value="" />
</form>
So, when user types Unicode search term and hits Enter, an HTTP Get request would be sent to the server with this URL:
http://www.example.com/search?search-term=مثال
This, in server would be:
http://www.example.com/search?search-term=%D9%85%D8%AB%D8%A7%D9%84
and I'm able to retrieve the decoded value of the search-term
query string using HttpContext.Current.Server.UrlDecode("%D9%85%D8%AB%D8%A7%D9%84")
which returns مثال
to me. Till here everything works fine and I have no problem.
However, if somebody type the aforementioned address directly in IE9, and hit Enter, then what I get at server is:
http://www.example.com/search?search-term=????
What's wrong here?
Update: We checked the traffic via Fiddler, and you can see the result in following pictures:
HTTP Get headers, captured by Fiddler, requested with Firefox
HTTP Get headers, captured by Fiddler, requested with IE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IE 不知道手动输入 URL 时要使用什么字符集,因此它必须使用默认字符集。当 Unicode 字符转换为不支持这些 Unicode 字符的 Ansi 字符集时,会出现
?
字符。当提交 Web 表单时,IE 使用 Web 表单的字符集,该字符集可以由 HTML 内的标记中的
IE does not know what charset you want to use when typing the URL manually, so it has to use a default charset.
?
characters occur when Unicode characters are converted to an Ansi charset that does not support those Unicode characters. When submitting a webform instead, IE uses the charset of the webform, which can be specified by the<form>
tag itself, in<meta>
tags within the HTML document, or the HTTPContent-Type
header, so there is less chance that IE has to guess the correct charset to use.