一段C#提取网页中某个文件内容的范例,还是很适用很方便的,立帖为证,方便后期再次适用,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string SourceCode;
private void Form1_Load(object sender, EventArgs e)
{
string url = "http://xxxx.com/link.txt";
getWebresourceFile5(url);
MessageBox.Show(SourceCode);
}
public string getWebresourceFile5(string url)
{
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
SourceCode = sr.ReadToEnd();
resStream.Close();
sr.Close();
return SourceCode;
}
private void saveSourceCode(string sourceCode)
{
throw new NotImplementedException();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(SourceCode);
}
}
}
亲爱的:若该文章解决了您的问题,可否收藏+评论+分享呢?
文章评论 本文章有个评论