[C#] 纯文本查看 复制代码
public partial class Form1 : Form
{
int i = 0;
string sLine;
string lint;
public Form1()
{
InitializeComponent();
xEngine.License.Init("半岛博客");
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 18000;
xEngine.Execute.Http execute = new xEngine.Execute.Http();
execute.LoadScript("半岛博客.x", false);
string[] f = Directory.GetFiles(@"C:\Users\admin\Desktop\data1", "*.txt");
if (i >= f.Length)
{
i = 0;
}
string s = f[i];
FileStream f1 = new FileStream(s, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(f1);
textBox1.Text = sr.ReadLine();
i++;
while (true)
{
lint = sr.ReadLine();
if (sr.EndOfStream)
{
break;
}
}
textBox2.Text = lint;
execute.Account.Account = textBox1.Text;
execute.Account.Password = textBox2.Text;
string[] files = Directory.GetFiles(@"C:\Users\admin\Desktop\data", "*.txt");
string flist = files[i];
FileStream filest = new FileStream(flist, FileMode.Open, FileAccess.Read);
StreamReader stre = new StreamReader(filest);
execute.Account.Other1 = stre.ReadLine();
execute.Account.Other3 = stre.ReadToEnd() + execute.Account.Other2;
StreamReader myStream = null;
myStream = new StreamReader(flist);
while (true)
{
sLine = myStream.ReadLine();//一行一行的读,如果前面的数据部需要就直接抛弃了
if (myStream.EndOfStream)
{//现在这个sLine 就是最后一行了
break;
}
}
execute.Account.Other2 = sLine;
sr.Close();
f1.Close();
filest.Close();
stre.Close();
richTextBox1.Text = "正在发布第" + i + "篇文章";
var response = execute.RunRequests();
string str = response.GetBodyStr();
if (str.Contains("登录失败,请检查您的用户名和密码"))
{
label6.Text = "发布失败,请检查你的用户名和密码";
}
else if (str.Contains("标题不能为空"))
{
label6.Text = "发布失败,请输入标题再发布";
}
else
{
label6.Text = "发布成功";
i++;
}
}
//} |