用GB2312的格式把textbox1的文本编码成字节流……
System.Text.ASCIIEncoding.GetEncoding("gb2312").GetBytes(textBox1.Text)
跳转前给你的URL编码,接收时给你的URL解码.就不会出现这个问题了这是javascript的函数.
encodeURI("url地址")//编码
decodeURI("url地址")//解码
这是asp.net的方法.
Server.UrlEncode("url地址")//编码
Server.UrlDecode("url地址")//解码
ps:可以用js编码.net解码.也就是它们编码解码方式是一样的.它们的返回值都是编码或解码后的字符串.
注:加到Page_Load()事件下面就可以了Encoding gb2312 = Encoding.GetEncoding("gb2312")
Response.ContentEncoding = gb2312
在非ASP.net 应用中,可能你读到的数据是UTF-8编码,但是你要转换为GB2312编码,则可以参考以下代码:
string utfinfo = "document.write(\"alert(你好么??)\")"
string gb2312info = string.Empty
Encoding utf8 = Encoding.UTF8
Encoding gb2312 = Encoding.GetEncoding("gb2312")
// Convert the string into a byte[].
byte[] unicodeBytes = utf8.GetBytes(utfinfo)
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(utf8, gb2312, unicodeBytes)
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] asciiChars = new char[gb2312.GetCharCount(asciiBytes, 0, asciiBytes.Length)]
gb2312.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0)
gb2312info = new string(asciiChars)
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)