Apache 如何从Haskell程序打印用于CGI的UTF-8字符串?
我想和Haskell一起做一个CGI程序。(使用Apache) 但我的程序无法正确打印UTF-8字符串Apache 如何从Haskell程序打印用于CGI的UTF-8字符串?,apache,haskell,utf-8,cgi,Apache,Haskell,Utf 8,Cgi,我想和Haskell一起做一个CGI程序。(使用Apache) 但我的程序无法正确打印UTF-8字符串 module Main where main :: IO() main = do { putStr("Content-type: text/plain; charset=utf-8\n\n"); putStr("English한글日本語abc"); } 通过telnet检查的结果为:
module Main where
main :: IO()
main = do
{
putStr("Content-type: text/plain; charset=utf-8\n\n");
putStr("English한글日本語abc");
}
通过telnet检查的结果为:
hhmm:appserve Eonil$ telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET http://localhost/cgi-bin/test HTTP\1.0
HTTP/1.1 200 OK
Date: Mon, 07 Mar 2011 07:31:28 GMT
Server: Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8l DAV/2
Connection: close
Content-Type: text/plain; charset=utf-8
EnglishConnection closed by foreign host.
hhmm:appserve Eonil$
问题出在哪里?我应该怎么做才能解决这个问题
该程序在命令行控制台上打印得很好。使用shell脚本构建的apache CGI很好地打印了UTF-8字符串。为了确保
putStr
使用正确的编码,您可以在stdout
上调用hSetEncoding
将其设置为“utf8”