gpt4 book ai didi

apache - 如何从 Haskell 程序中为 CGI 打印 UTF-8 字符串?

转载 作者:行者123 更新时间:2023-12-02 08:26:08 25 4
gpt4 key购买 nike

我正在尝试用 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检查的结果是:

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$

问题是什么?我应该采取什么措施来解决这个问题?

PS。该程序在命令行控制台上打印得很好。使用shell脚本构建的apache CGI可以很好地打印UTF-8字符串。

最佳答案

要确保 putStr 使用正确的编码,您可以在 stdout 上调用 hSetEncoding 将其设置为 “utf8”.

http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.3.1.0/System-IO.html#g:23

关于apache - 如何从 Haskell 程序中为 CGI 打印 UTF-8 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5217022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com