日期:2014-05-18  浏览次数:20878 次

发送给网站的中文字成乱码???
我在WINFORM程序中有如下的语名发送信息给网站,发送成功,但是保存到网站的信息其中的中文字“李平”变成了不认识的乱码,数字和字母的信息没有变化,可以识别。请问是什么原因??
  Public   Sub   postweb()
                '向服务器POST信息:
                Dim   httpUrl2   As   New   System.Uri( "http://192.168.0.8/jizhan/201.asp?ip6=zuo7&xinmin=李平 ")   '   “&”号后面是 '注册信息,改成你自己的
                Dim   req   As   HttpWebRequest
                req   =   CType(WebRequest.Create(httpUrl2),   HttpWebRequest)
                req.Method   =   "POST "
                req.ContentType   =   "application/x-www-form-urlencoded "
                Dim   bytesData()   As   Byte   =   System.Text.Encoding.ASCII.GetBytes( " ")
                req.ContentLength   =   bytesData.Length
                Dim   postStream   As   Stream   =   req.GetRequestStream()
                postStream.Write(bytesData,   0,   bytesData.Length)       '以上为向网络服务器POST信息
                Dim   res   As   HttpWebResponse   =   CType(req.GetResponse(),   HttpWebResponse)
                Dim   reader   As   StreamReader   =   New   StreamReader(res.GetResponseStream,   System.Text.Encoding.GetEncoding( "GB2312 "))
                Dim   respHTML   As   String   =   reader.ReadToEnd()     'respHTML为POST后网络服务器返回的信息
                TextBox1.Text   =   respHTML                     '可用MsgBox查看返回的信息
                res.Close()

        End   Sub


------解决方案--------------------
System.Text.Encoding.GetEncoding( "GB2312 ")
--> >
Encoding.Unicode;
Encoding.UTF8;

换两种编码试试
------解决方案--------------------

'编码
Encoding encoding = System.Text.Encoding.Default;
byte[] cncodedBytes = encoding.GetBytes();

'解码
string decodedString = encoding.GetString(cncodedBytes);