Cookies and HttpWebRequest
-
Hey Lads, I'm using HttpWebRequest in a thick client application and just wondering if there is a simple way to get the request to automatically include an IE cookie??? Regards, Brian Dela :-) http://www.briandela.com IE 6 required.
http://www.briandela.com/pictures Now with a pictures section :-D
http://www.briandela.com/rss/newsrss.xml RSS Feed -
Hey Lads, I'm using HttpWebRequest in a thick client application and just wondering if there is a simple way to get the request to automatically include an IE cookie??? Regards, Brian Dela :-) http://www.briandela.com IE 6 required.
http://www.briandela.com/pictures Now with a pictures section :-D
http://www.briandela.com/rss/newsrss.xml RSS FeedNot through the BCL, no. You can P/Invoke
InternetGetCookie
:[DllImport("wininet.dll", CharSet=CharSet.Auto)]
private static extern bool InternetGetCookie(
string url,
string cookieName,
[Out] string cookieData,
ref int dataSize);That third parameter should not use
out
, mind you - it should be marshaled as an [out] param using theOutAttribute
only, otherwise the CLR will crash. See the Platform SDK for usage, but it's really pretty easy to do. To easily allocate a string of a certain size, you can usenew string('\0', _size_)
or declare those asStringBuilder
s and modify your source accordingly. Then you can parse and include these in yourCookieContainer
for use with theHttpWebRequest
.Microsoft MVP, Visual C# My Articles