C#登录代码不起作用
此代码将从文本文件中获取用户名和密码,在下一个if(此处未显示)中,将检查登录名是否与文件中的相同C#登录代码不起作用,c#,C#,此代码将从文本文件中获取用户名和密码,在下一个if(此处未显示)中,将检查登录名是否与文件中的相同 private void Form1_Load(object sender, EventArgs e) { var webClient = new WebClient(); string readHtml = webClient.DownloadString("http://yourdomain.com/yourfolder/vars.txt");
private void Form1_Load(object sender, EventArgs e)
{
var webClient = new WebClient();
string readHtml = webClient.DownloadString("http://yourdomain.com/yourfolder/vars.txt");
string line = "";
while ((line == webClient.readHtml()) != null)
{
string[] components = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
users.Add(components[0]);
pass.Add(components[1]);
}
TimeLabel.Text = (DateTime.Now.ToString() + " System time at load");
Text = "Admin Login";
}
很像StreamReader中的代码读取行,例如,每次读取一行
WebClient.DownloadString(string)
但是将整个文件读入一个字符串。所以你得做点像这样的事才能得到一条线
string line = "";
while ((line == webClient.readHtml()) != null)
string[]splt=readHtml.Split('\n')//或换行符的不同表示形式
对于(int i=0;iSo….我们要猜测什么不起作用吗?是的,我不知道任何修复程序。您必须告诉我们它是如何起作用的。您是否遇到错误?您是否使用调试器逐步完成了该方法?webclient.readHtml()的webclient
类没有readHtml()
方法(这就是错误告诉你的)-即使它这样做了,它也会用大写字母R
(因为这是C#的命名约定)。因此,不清楚您希望该方法做什么或它应该来自何处。我最好的猜测是您希望使用您拥有的readHtml
字符串变量做些什么,但我不知道是什么,因为(line==readHtml)!=null
也没有多大意义
string[] splt=readHtml.Split('\n');//or different presentation of line break
for(int i=0; i<splt.Length; i++){
//split your components from splt[i] here
//and add them to your attributes or whatever
}