2

I find that the snap show the utf-8 encoded text as unreadable characters, the code and results like:

{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text as T

...

site :: Snap ()
site =
    ifTop (writeText $ T.pack "hello world! 你好") <|> -- Here is the utf-8 text
    route [ ("foo", writeBS "bar")
          , ("query/:pat", echoHandler)
          ] <|> 
    dir "static" (serveDirectory ".")

the output in browser is:

hello world! ä½ å¥½

I search stackoverflow and find there's a similar question (How to show utf8 text with snap and heist?), but it seems does not work. How can I handle this utf-8 problem ?

Community
  • 1
  • 1
hliu
  • 1,015
  • 8
  • 16
  • there are a couple of things here: is your source-file saved as UTF8? (does GHC understand it: https://stackoverflow.com/questions/6797902/haskell-source-encoding), is the encoding set for snap (see your linked question here), ... have you tried the solution shown by the accepted answer there? – Random Dev May 04 '15 at 13:36
  • 8
    It looks like your server did send UTF-8 encoded text, but your browser interpreted it as ISO-8859-1. You probably need to set an HTTP content encoding header. – Reid Barton May 04 '15 at 13:39
  • The answer in the linked question shows how to set the content-type. Isn't this a duplicate? – Mokosha May 05 '15 at 02:17

0 Answers0