2011-04-26 65 views
3

我正在使用带有UTF-8数据的CGI::Application使用CGI获取latin1而不是UTF-8 ::应用程序

在HTML具有予置编码UTF-8像这样

<!DOCTYPE html> 
<html dir="ltr"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    </head> 
    <body> 

但输出被当作latin1的,作为特殊字符显示为2个字符。

Firefox中的页面信息显示页面编码为ISO-8859-1,尽管有HTML标头。

我一直只能找到这些twoposts关于这个问题,但他们是旧的,非常复杂。

任何已解决此问题的人?

更新:这里是FireBug的HTTP头。

Response Headers 
Date Tue, 26 Apr 2011 09:53:24 GMT 
Server Apache/2.2.3 (CentOS) 
Connection close 
Transfer-Encoding chunked 
Content-Type text/html; charset=ISO-8859-1 

Request Headers 
Host example.com 
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:2.0) Gecko/20100101 Firefox/4.0 
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language en-gb,en;q=0.5 
Accept-Encoding gzip, deflate 
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive 115 
Connection keep-alive 

我注意到,如果我强迫UTF-8 FireFox->Web Developer->Character Encoding->Unicode (UTF-8),如果看起来是正确的。

+0

你的HTTP头文件是什么样的? (Firebug可以告诉你) – Quentin 2011-04-26 09:03:54

+1

尝试添加'binmode(STDOUT,':utf8');'到你的cgi文件。 – n0rd 2011-04-26 09:47:59

+0

@ n0rd更改为不同的编码,但仍然看起来不正确。 – 2011-04-26 10:10:44

回答

5

你的HTTP头:

内容类型text/html;字符集= ISO-8859-1

...索赔拉丁1.实时HTTP标头优先于HTML <meta>数据的文档进行编码。

$webapp->header_add(-type => 'text/html; charset=UTF-8'); 

...如果我正确地阅读文档,应该做这项工作。