Unable to Retrieve Simplified Chinese Characters From Form

Posted by Bullines on Stack Overflow See other posts from Stack Overflow or by Bullines
Published on 2010-03-26T15:08:39Z Indexed on 2010/03/26 20:23 UTC
Read the original article Hit count: 431

Filed under:
|

I have a page that displays content retrieved from XML with no problems:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <Fields>
        <NamePrompt>??</NamePrompt>
    </Fields>
</Root>

Page encoding is set to GB18030 and it displays perfectly. However, when I retrieve inputted text from HttpContext.Current.Request.Form that's been entered with double-byte characters, the retrieved string contains unreadable characters. Single-byte characters are fine, obviously.

I've tried the following to no avail:

byte[] valueBytes = Encoding.UTF8.GetBytes(HttpContext.Current.Request.Form["fullName"]);
string value = Encoding.UTF8.GetString(valueBytes);

I don't see this problem with other double-byte languages like Japanese or Korean. How can I successfully retrieve double-byte characters from a page that's GB18030 encoded?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about character-encoding