Autor Beitrag
BigX_Jazz
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Sa 14.01.12 03:10 
Hallo,
Ich hab schon ewig gegoogelt und leider nichts passendes gefunden:/
Ich möchte bei nem vBulletin Forum gerne einen Thread erstellen. ich hab eine Login Methode und eine NewThread Methode geschrieben.. Login klappt, das andere nicht:/ HILFE!


ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
        static string login(string url, string username, string password)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            string cookie = "";
            string values = "&vb_login_username=" + username + "&vb_login_password=" + password
                                + "&securitytoken=guest&"
                                + "&cookieuser=1&"
                                + "&do=login"
                                + "&url=/newthread.php?do=newthread&f=119"
                                + "&postvars=7b4c7f046373dad64bf56253cdc47e78894b3b1ba:24:{s:8:\"prefixid\";s:8:\"Komoedie\";s:7:\"subject\";s:10:\"30 Minueten\";s:7:\"message\";s:16:\"Das ist der Film\";s:7:\"wysiwyg\";s:1:\"0\";s:6:\"iconid\";s:1:\"0\";s:1:\"s\";s:0:\"\";s:13:\"securitytoken\";s:51:\"1326372962-2e6d7f563f4f1aa04107112d09055937110313ab\";s:1:\"f\";i:119;s:2:\"do\";s:10:\"postthread\";s:8:\"posthash\";s:0:\"\";s:13:\"poststarttime\";s:0:\"\";s:12:\"loggedinuser\";s:5:\"18837\";s:7:\"sbutton\";s:15:\"Thema erstellen\";s:10:\"podcasturl\";s:0:\"\";s:11:\"podcastsize\";s:0:\"\";s:15:\"podcastsubtitle\";s:0:\"\";s:15:\"podcastkeywords\";s:0:\"\";s:13:\"podcastauthor\";s:0:\"\";s:8:\"parseurl\";s:1:\"1\";s:11:\"emailupdate\";s:4:\"9999\";s:11:\"polloptions\";s:1:\"4\";s:7:\"forumid\";R:9;s:4:\"ajax\";i:0;s:8:\"postvars\";N;}";
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = values.Length;
            CookieContainer a = new CookieContainer();
            req.CookieContainer = a;

            System.Net.ServicePointManager.Expect100Continue = false// prevents 417 error

            using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)) 
            { 
                writer.Write(values); 
            }

            HttpWebResponse c = (HttpWebResponse)req.GetResponse();
            foreach (Cookie cook in c.Cookies) { cookie = cookie + cook.ToString() + ";"; }

            return cookie;
        }

        public static void CreateNewThread(string url, string fId, string title, string message, string tag)
        {
            String log_cookie = login("http://mygully.com/login.php""entfernt""entfernt");
            String userid = Regex.Split(log_cookie, "id=")[1].Split(';')[0];

            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

                string values = "subject=" + title
                        + "&message=" + message
                        + "&tag=" + tag
                        + "&do=postthread"
                        + "&f=" + fId
                        + "&s="
                        + "&wysiwyg=0"
                        + "&iconid=0"
                        + "&poststarttime=0"
                        + "&loggedinuser=" + userid
                        + "&sbutton=Thema erstellen"
                        + "&parseurl=1"
                        + "&emailupdate=9999"
                        + "&polloptions=4"
                        + "&securitytoken01326406142-64c3d9d0769ece9e729ff2f6d1d7975698d28f9b"
                        ;

                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = values.Length;

                ServicePointManager.Expect100Continue = false// prevents 417 error

                using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), Encoding.UTF8))
                {
                    writer.Write(values);
                }


                HttpWebResponse c = (HttpWebResponse)req.GetResponse();
            }

            catch (Exception e)
            {
                MessageBox.Show("Fehler:"+ e);
            }
        }


Moderiert von user profile iconMartok: C#-Tags hinzugefügt
Moderiert von user profile iconMartok: Topic aus Internet / Netzwerk verschoben am Sa 14.01.2012 um 03:43
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 14.01.12 10:10 
Hallo und :welcome:

Ich kenne das zwar in C# nicht, aber nach meinen Erfahrungen mit dem Thema in Delphi hätte ich erwartet, dass der CookieContainer der ersten Anfrage bei der zweiten einfach wieder im Request hängen muss, damit die Cookies wieder als solche zur Verfügung stehen.

Denn schließlich muss die Session ja vom Server identifiziert werden können.