【问题标题】:Writing cookies from CookieContainer to the IE cookie store using c#使用 c# 从 CookieContainer 将 cookie 写入 IE cookie 存储
【发布时间】:2015-08-17 16:06:36
【问题描述】:

尝试将我在 .NET 应用程序中收到的 cookie 保存到 IE cookie 存储区时遇到了一些麻烦。

我有一个请求(带有其他参数,未显示)

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

响应获取 cookie。

[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);
                    }

我尝试关注Writing cookies from CookieContainer to the IE cookie store,但我无法让 InternetSetCookie 工作。它似乎没有在本地创建 cookie。

有什么建议吗?

【问题讨论】:

    标签: c# internet-explorer cookies setcookie


    【解决方案1】:

    我明白了...看起来这只是设置会话cookie。 此外,必须有一个有效的 URL。

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

    InternetSetCookie 是布尔型,它返回“false”,当我设置一个有效的 URL 时,它开始返回“True”,这似乎对我有用。

    【讨论】:

      猜你喜欢
      • 2011-04-09
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-02
      • 1970-01-01
      相关资源
      最近更新 更多