Autor Beitrag
ebber
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Fr 21.09.12 23:22 
Hallo,

ich habe ein paar Cookies. Diese möchte ich jetzt gerne an den Browser übergeben. Also an ein WebBrowser Control in meinem Programm.

Gefunden habe ich dazu folgendes:
ausblenden C#-Quelltext
1:
2:
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);

ausblenden C#-Quelltext
1:
InternetSetCookie("xxx.de""sth""123");					


Leider macht das irgendwie nichts. Es gibt jedoch true zurück.

Wenn ich in dem WebBrowser von irgendeiner Seite ein cookie bekomme landet das hier: "C:\Users\xxx\AppData\Local\Microsoft\Windows\Temporary Internet Files". Mit "InternetSetCookie" leider nicht.

Funktioniert das so garnicht? Funktioniert das irgendwie anders?

MfG
Flitzs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 123
Erhaltene Danke: 7

Win7 x64/86 WinServer 2008 R2 x64
C#/C++/C VS2010
BeitragVerfasst: Sa 22.09.12 19:54 
Zitat:
Cookies created by InternetSetCookie without an expiration date are stored in memory and are available only in the same process that created them. Cookies that include an expiration date are stored in the windows\cookies directory.

Quelle: msdn.microsoft.com/e...5107%28VS.85%29.aspx

Könnte das vielleicht der Grund sein?
ebber Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Sa 22.09.12 20:55 
Danke, mir scheint ich habe die Lösung dadruch gefunden. Die Funktion funktioniert irgendwie nicht wirklich wie man denken könnte.

Richtig:

ausblenden C#-Quelltext
1:
InternetSetCookie("xxx.de"null"sth=123");					


und nach Bedarf:
ausblenden C#-Quelltext
1:
2:
// Es steht geschrieben, dass man genau dieses Datumsformat braucht
InternetSetCookie("xxx.de"null"sth=123; expires = Sat,01-Jan-2014 00:00:00 GMT");


Und Falls jemand auch noch dieses Problem haben sollte, welches ich ganz am Anfang hatte: die url muss mit "http://" beginnen. Sonst liefert die Funktion false zurück. Jedoch scheint es mir als sollte man danach auf das www verzichten, also:
ausblenden Quelltext
1:
http://xxx.de					

So kommen sie zumindest im gleichen Format an, wie sie der Internet Explorer direkt rausgibt.

MfG