Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. InternetGetCookie returning false always,plz help me to read cookie value from VC++

InternetGetCookie returning false always,plz help me to read cookie value from VC++

Scheduled Pinned Locked Moved ATL / WTL / STL
helpc++comquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rindam
    wrote on last edited by
    #1

    InternetGetCookie function is always returning false.I am giving u the code here,can u plz tell me where the mistake is? ------------------------------------------------------------------------------- char szURL[256]="http://www.mirracle.com"; LPWSTR lpszData = NULL; // buffer to hold the cookie data DWORD dwSize=255; // variable to get the buffer size needed LPCWSTR usrauth =NULL; BOOL result=InternetGetCookie(szURL,usrauth,lpszData,&dwSize); DWORD ret; if(result==FALSE) { ret = GetLastError(); if (ret == ERROR_NO_MORE_ITEMS) MessageBox(NULL,_T("no items"),NULL,MB_OK); else if(ret == ERROR_INSUFFICIENT_BUFFER) MessageBox(NULL,_T("insufficient buffer"),NULL,MB_OK); else if(ret == ERROR_INVALID_PARAMETER) MessageBox(NULL,_T("invalid parameters"),NULL,MB_OK); } else { MessageBox(NULL,lpszData,NULL,MB_OK); } The InternetGetCookie function is always returning false here and I am not being able to get the cookie value for this particular site.Plz help me.

    S 1 Reply Last reply
    0
    • R rindam

      InternetGetCookie function is always returning false.I am giving u the code here,can u plz tell me where the mistake is? ------------------------------------------------------------------------------- char szURL[256]="http://www.mirracle.com"; LPWSTR lpszData = NULL; // buffer to hold the cookie data DWORD dwSize=255; // variable to get the buffer size needed LPCWSTR usrauth =NULL; BOOL result=InternetGetCookie(szURL,usrauth,lpszData,&dwSize); DWORD ret; if(result==FALSE) { ret = GetLastError(); if (ret == ERROR_NO_MORE_ITEMS) MessageBox(NULL,_T("no items"),NULL,MB_OK); else if(ret == ERROR_INSUFFICIENT_BUFFER) MessageBox(NULL,_T("insufficient buffer"),NULL,MB_OK); else if(ret == ERROR_INVALID_PARAMETER) MessageBox(NULL,_T("invalid parameters"),NULL,MB_OK); } else { MessageBox(NULL,lpszData,NULL,MB_OK); } The InternetGetCookie function is always returning false here and I am not being able to get the cookie value for this particular site.Plz help me.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      The way you've specified the output buffer is wrong - YOU have to allocate that buffer - the function won't do it for you. At the moment, you're telling th efunction to put teh cookie data at address zero - always a bad idea. This code seems to work (OK, I've used a different URL - just replace mine with yours):

      TCHAR buffer [16384];
         DWORD bufferSize = sizeof(buffer)/sizeof(buffer[0]);
         BOOL bRes = InternetGetCookie(_T("http://www.codeproject.com"), 0, buffer, &bufferSize);

      R 1 Reply Last reply
      0
      • S Stuart Dootson

        The way you've specified the output buffer is wrong - YOU have to allocate that buffer - the function won't do it for you. At the moment, you're telling th efunction to put teh cookie data at address zero - always a bad idea. This code seems to work (OK, I've used a different URL - just replace mine with yours):

        TCHAR buffer [16384];
           DWORD bufferSize = sizeof(buffer)/sizeof(buffer[0]);
           BOOL bRes = InternetGetCookie(_T("http://www.codeproject.com"), 0, buffer, &bufferSize);

        R Offline
        R Offline
        rindam
        wrote on last edited by
        #3

        here also this function is returning false.whats the problem?

        R 1 Reply Last reply
        0
        • R rindam

          here also this function is returning false.whats the problem?

          R Offline
          R Offline
          rindam
          wrote on last edited by
          #4

          I have tried with the below code: TCHAR buffer [16384]; DWORD bufferSize = sizeof(buffer)/sizeof(buffer[0]); BOOL bRes = InternetGetCookieA(("http://www.mirracle.com"), name, (LPSTR)buffer, &bufferSize); this code is working fine .but I need to get the cookie value,How can I get it?

          S 1 Reply Last reply
          0
          • R rindam

            I have tried with the below code: TCHAR buffer [16384]; DWORD bufferSize = sizeof(buffer)/sizeof(buffer[0]); BOOL bRes = InternetGetCookieA(("http://www.mirracle.com"), name, (LPSTR)buffer, &bufferSize); this code is working fine .but I need to get the cookie value,How can I get it?

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            The string in buffer is the value. It's stored in an encoded form, as described here[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups