开发者

Unable to Retrieve Simplified Chinese Characters From Form

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 va开发者_运维百科lue = 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?


What platform is the code running on? According to this, GB18030 was not supported at all before Win2K, and not natively until WinXP.

If that isn't the problem, we'll need more details. How do you know the characters are unreadable? Are you trying to display them somewhere other than the browser? At this point, we can only assume it's a font problem, or an encoding-conversion problem in code that you haven't shown us.

By the way, the code you did post doesn't really do anything--just a perfectly safe (and pointless) round-trip from .NET string to UTF-8 byte array and back again. But that's a dead-end anyway; if the string returned by

HttpContext.Current.Request.Form["fullName"]

...is corrupt, that's the problem you have to solve. Repairing the string after the fact (if that's even possible) is no solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜