展开全部
文本框1,输入地址,文本框2显示源码。点击按钮开始获取。关键注意编码,我写了两个,有些网站是utf-8编码,有些是默认,如果一个不行就换另外一个
private void button1_Click(object sender, EventArgs e)
{
WebRequest request = WebRequest.Create(textBox1.Text);//实例化WebRequest对象
WebResponse response = request.GetResponse();//创建WebResponse对象
Stream datastream = response.GetResponseStream();//创建流对象
Encoding ec = Encoding.UTF8;
Encoding EC = Encoding.Default;
StreamReader reader = new StreamReader(datastream, EC);
string responseFromServer = reader.ReadToEnd();//读取数据
richTextBox1.AppendText(responseFromServer);//添加到RichTextBox控件中
reader.Close();
datastream.Close();
response.Close();
}
private void button1_Click(object sender, EventArgs e)
{
WebRequest request = WebRequest.Create(textBox1.Text);//实例化WebRequest对象
WebResponse response = request.GetResponse();//创建WebResponse对象
Stream datastream = response.GetResponseStream();//创建流对象
Encoding ec = Encoding.UTF8;
Encoding EC = Encoding.Default;
StreamReader reader = new StreamReader(datastream, EC);
string responseFromServer = reader.ReadToEnd();//读取数据
richTextBox1.AppendText(responseFromServer);//添加到RichTextBox控件中
reader.Close();
datastream.Close();
response.Close();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询