我准备通过程序在一个新的IE窗口内打开一个网址,想先设一个临时Cookie,不知道怎么实现,那位大侠能帮忙提供一些资料?

解决方案 »

  1.   

    使用InternetSetCookieEx函数.
      

  2.   

    Managing Cookies--------------------------------------------------------------------------------Setting a Cookie
    InternetSetCookie is used to set a cookie on the specified URL. InternetSetCookie can create both persistent and session cookies.Persistent cookies are cookies that have an expiration date. These cookies are stored in the Windows\System directory.Session cookies are stored in memory and can be accessed only by the process that created them.The data for the cookie should be in the format:NAME=VALUE
    For the expiration date, the format must be:DAY, DD-MMM-YYYY HH:MM:SS GMT
    DAY is the three-letter abbreviation for the day of the week, DD is the day of the month, MMM is the three-letter abbreviation for the month, YYYY is the year, and HH:MM:SS is the time of the day in military time.The following example demonstrates two calls to InternetSetCookie. The first call creates a session cookie and the second creates a persistent cookie.BOOL bReturn;// Create a session cookie.
    bReturn = InternetSetCookie("http://www.adventure_works.com", NULL,
                "TestData = Test");

    // Create a persistent cookie.
    bReturn = InternetSetCookie("http://www.adventure_works.com", NULL,
                 "TestData = Test; expires = Sat, 01-Jan-2000 00:00:00 GMT");
      

  3.   

    可能是我没描述清楚吧:
    我需要的是点一下一个Button,程序弹出一个网页(比如使用ShellExecute),网页打开一个网址,而不是用程序去读网页数据
      

  4.   

    并没有让你用程序去读网页数据,而是在你弹出网页之前,使用InternetSetCookie函数设置cookie,然后当你用ShellExecute打开网页后,这个cookie将被http协议使用.这应该是你的用户需求,如果不合你意的话,说明"可能是你还没描述清楚".
      

  5.   

    程序中使用
    InternetSetCookie(_T("http://server"), NULL, _T("userid=2"));
    ShellExecute(hWnd, _T("open"), LinkUrl, NULL, NULL, SW_SHOWNORMAL);
    还是没有用
      

  6.   

    ShellExecute执行后是创建新的process,Session cookies没有被设置上去
      

  7.   

    请详细阅读InternetSetCookie函数说明,你的cookie"没有被设置上去
    " 是因为第一个参数与ShellExecute中的LinkUrl不匹配造成的.
      

  8.   

    LinkUrl=_T("http://server/html"),应该没影响吧?我自己测试过即使一致也不行.
    根据laiyiling转MSDN的原话来看:
    ShellExecute执行后是创建新的process,但是Session cookies are stored in memory and can be accessed only by the process that created them.
      

  9.   

    cookie分为永久性和临时性两种,请详细阅读MSDN中有关cookie部份,弄清其基本概念.你所要创建(预设)的是永久性cookie.