c#利用webclient类库发送WEB请求时,乱码

dujunli 2004-12-26 01:57:46
我利用c#提供的类库webclient采用POST方式向另一台运行PHP的WEB服务器发送WEB请求,但是接收到的却是乱码!
我想可能是C#采用的是UNICODE的编码方式,怎么将UNICODE转为GBK编码方式?
...全文
216 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2004-12-26
  • 打赏
  • 举报
回复
把你的POST数据先用HttpUtility.UrlEncode转换

string s = "abc=" + HttpUtility.UrlEncode("转换", System.Text.Encoding.Default);

or

string s = "abc=" + HttpUtility.UrlEncode("转换", System.Text.Encoding.GetEncoding("GB2312"));
webserv2 2004-12-26
  • 打赏
  • 举报
回复
Dim sr As StreamReader = New StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default)
webserv2 2004-12-26
  • 打赏
  • 举报
回复
Public Shared Function GetDate(ByVal strUrl As String) As String
Dim html As String = ""

Dim resp As HttpWebResponse
Dim req As HttpWebRequest = CType(HttpWebRequest.Create(strUrl), HttpWebRequest)
req.Timeout = 15000
resp = CType(req.GetResponse(), HttpWebResponse)
Dim sr As StreamReader = New StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default)
html = sr.ReadToEnd()

Return html
End Function

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧