0

I am having a bit of trouble trying to save the cookies i receive in my .NET application onto IE cookie store.

I have a request (with other parameters, not shown)

HttpWebRequest request = HttpWebRequest.Create(RequestString) as HttpWebRequest;

the response gets cookies.

[DllImport("wininet.dll", CallingConvention = CallingConvention.Cdecl)]
        static extern bool InternetSetCookie(string UrlName, string CookieName, string CookieData, uint dwFlags, IntPtr dwReserved);

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    foreach (Cookie cookie in response.Cookies)
                    {
                        InternetSetCookie(cookie.Domain, cookie.Name, cookie.Value, 2147484672, IntPtr.Zero);
                    }

I tried to follow Writing cookies from CookieContainer to the IE cookie store but i am not able to get InternetSetCookie to work. It just doesn't seem to create cookies locally.

Any suggestions?

Community
  • 1
  • 1
Telson Alva
  • 842
  • 6
  • 22
  • 37

1 Answers1

0

I got this figured out ... looks like this is only sets the session cookies. Also, there must be a valid URL.

InternetSetCookie(ValidURL, cookie.Name, cookie.Value);

InternetSetCookie is bool and it was returning 'false', when i set a valid URL, it started returning 'True' and that seemed to be working for me.

Telson Alva
  • 842
  • 6
  • 22
  • 37