C# Webrequest + Cookie via CookieCollection Emtpy Value Problem

Devilzimti

Grünschnabel
Hallo,
ich habe folgendes Problem:
Ich möchte eine Webseite unter Übergabe von Cookies aufrufen.
Relevanter Ausschnitt aus meinem Code:
Code:
// Create the request obj
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.*************************.php?module=Rating&args=" + Random.Next(1, 124882)  + "&*************************&*************************=" + Random.Next(1, 5));

            // Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.CookieContainer = new CookieContainer();
            

            
            // Set Data
            CookieCollection CookieCollection1 = new CookieCollection();
            CookieCollection1.Add(new Cookie("__utmz", "*************************"));
            CookieCollection1.Add(new Cookie("__utma", "*************************"));
            CookieCollection1.Add(new Cookie("__utmb", "*************************"));
            CookieCollection1.Add(new Cookie("__utmc", "*************************"));
            CookieCollection1.Add(new Cookie("SK_SESSID", "*************************"));
            CookieCollection1.Add(new Cookie("SK_LOGIN", "*************************"));

            req.CookieContainer.Add((CookieCollection) CookieCollection1);

Beim Ausführen meldet mir der Debugger in der Zeile
Code:
            req.CookieContainer.Add((CookieCollection) CookieCollection1);
folgenden Fehler:
System.ArgumentException wurde nicht behandelt.
Message="Der Parameter {0} kann keine leere Zeichenfolge sein.\r\nParametername: cookie.Do*****"
Source="System"
ParamName="cookie.Do*****"
StackTrace:
bei System.Net.CookieContainer.Add(Cookie cookie)
bei System.Net.CookieContainer.Add(CookieCollection cookies)
bei Partykumpel.de.Form1.HttpRequestKronkorken(String Cookie) in C:\Dokumente und Einstellungen\*****\Eigene Dateien\Visual Studio 2005\Projects\Partykumpel.de\Partykumpel.de\Form1.cs:Zeile 52.
bei Partykumpel.de.Form1.button1_Click(Object sender, EventArgs e) in C:\Dokumente und Einstellungen\*****\Eigene Dateien\Visual Studio 2005\Projects\Partykumpel.de\Partykumpel.de\Form1.cs:Zeile 25.
bei System.Windows.Forms.Control.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
bei System.Windows.Forms.Button.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.Run(Form *****Form)
bei Partykumpel.de.Program.*****() in C:\Dokumente und Einstellungen\*****\Eigene Dateien\Visual Studio 2005\Projects\Partykumpel.de\Partykumpel.de\Program.cs:Zeile 17.
bei System.AppDo*****.nExecuteAssembly(Assembly assembly, String[] args)
bei System.AppDo*****.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()

Ich denke, dass die 2. Überladung: method(cookiecollectiom cookie)
auf mein Beispiel zutreffen müsste.

Danke für die Hilfe
 
Zuletzt bearbeitet:
Zurück