Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过txt文件读取凭据并尝试登录c#?_C# - Fatal编程技术网

通过txt文件读取凭据并尝试登录c#?

通过txt文件读取凭据并尝试登录c#?,c#,C#,我将为函数创建一个循环,并在catch中为所有失败的登录打印消息,并为所有良好的登录打印“Successful connected with…”。 现在我尝试使用该代码,但在catch的textbox中只有一个错误 按钮1: if (openFileDialog1.FileName != string.Empty) { using (StreamReader reader = new StreamReader(openF

我将为函数创建一个循环,并在catch中为所有失败的登录打印消息,并为所有良好的登录打印“Successful connected with…”。 现在我尝试使用该代码,但在catch的textbox中只有一个错误

按钮1:

  if (openFileDialog1.FileName != string.Empty)
                {
                    using (StreamReader reader = new StreamReader(openFileDialog1.FileName))
                    {
                        int count = 0;
                        string lineoflistemail;
                        while ((lineoflistemail = reader.ReadLine()) != null)
                        {
                            UserData d = new UserData();
                            string[] parts = lineoflistemail.Split(':');
                            count = parts.Length;
                            d.UserName = parts[0].Trim();
                            d.Password = parts[1].Trim();
                            data.Add(d);
                        }

                        foreach(UserData ud in data)
                        {
                            textBox1.Text += ("LOL" + ud.UserName + ud.Password + Environment.NewLine);
                        }
第二个按钮代码:

if (data.Count() == 0)
            {
                MessageBox.Show("Load user info first");
                return;
            }

            for( hola = 0; hola < data.Count(); hola++) 
            {


            var url = @"https://mail.google.com/mail/feed/atom";
            var encoded = TextToBase64(data[0].UserName + ":" + data[1].Password);
            var myweb = HttpWebRequest.Create(url) as HttpWebRequest;
            myweb.Method = "POST";
            myweb.ContentLength = 0;
            myweb.Headers.Add("Authorization", "Basic " + encoded);
            var response = myweb.GetResponse();
            var stream = response.GetResponseStream();
            textBox1.Text += ("Connection established with");
            MessageBox.Show(hola.ToString());
        }

        }

        catch (Exception ex)
        {
            textBox1.Text += ("Error connection. Original error: " + ex.Message);
        }

        }
if(data.Count()==0)
{
MessageBox.Show(“首先加载用户信息”);
返回;
}
对于(hola=0;hola
问题是您的
try…catch
超出了
for
循环。第一个异常将退出
for
循环,将消息附加到
textBox1
,然后退出按钮处理程序

如果即使出现错误也要继续循环,请将
try…catch
移动到循环内部。下面是一个例子:

for( hola = 0; hola < data.Count(); hola++) 
{
    var url = @"https://mail.google.com/mail/feed/atom";
    var encoded = TextToBase64(data[0].UserName + ":" + data[1].Password);
    var myweb = HttpWebRequest.Create(url) as HttpWebRequest;
    myweb.Method = "POST";
    myweb.ContentLength = 0;
    myweb.Headers.Add("Authorization", "Basic " + encoded);

    try
    {
        var response = myweb.GetResponse();
        var stream = response.GetResponseStream();
        textBox1.Text += ("Connection established with");
        MessageBox.Show(hola.ToString());
    }
    catch (Exception ex)
    {
        textBox1.Text += ("Error connection. Original error: " + ex.Message);
    }
}
for(hola=0;hola
错误是。。。。。。?这看起来也像是你在尝试电子邮件的用户名/密码组合。粗略地说,我有一个随机字符列表,只是想试试,我知道我会出错,但我想得到它的所有假帐户它的工作都很好。非常感谢,伙计。只是一个问题,它应该像成功登录那样运行=?