读取远程文件,返回乱码,请大家帮忙解决

cwchyt 2007-09-15 01:30:00
返回后,string yuancheng接收到的字符,很多是乱码,大家帮忙解决一下,谢谢


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;

using System.Text.RegularExpressions;
using System.IO;

namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string url = "http://d.baidu.com/rs.php?q=山东";

//创建请求对象
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
//接收(回应)请求对象返回的信息,也就是源代码
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//最后,将获取的信息读出来
StreamReader sr = new StreamReader(response.GetResponseStream(),Encoding.GetEncoding ("gb2312"));
//读取内容到字符串
string yuancheng = sr.ReadToEnd(); //**取到的值中间部分乱码**
//关闭读取流,并释放资源
response.Close();
sr.Close();
}
}
}
...全文
135 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
破碎的脸 2007-09-15
  • 打赏
  • 举报
回复
来晚了
cwchyt 2007-09-15
  • 打赏
  • 举报
回复
问题已解决,原来是url路径格式不对,结贴
cwchyt 2007-09-15
  • 打赏
  • 举报
回复
大家帮忙看看啊,拜托....
cwchyt 2007-09-15
  • 打赏
  • 举报
回复
UTF-8也不行,全部是乱码
flaigd 2007-09-15
  • 打赏
  • 举报
回复
Encoding.GetEncoding ("gb2312"))

你读去的辑码要和文档的编码一致,你可以试试UTF-8
cwchyt 2007-09-15
  • 打赏
  • 举报
回复
顶起来

110,533

社区成员

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

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

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