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. C / C++ / MFC
  4. Download file using CInternetSession [modified]

Download file using CInternetSession [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminagentic-aiquestion
8 Posts 4 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.
  • J Offline
    J Offline
    john5632
    wrote on last edited by
    #1

    Hi, I am trying to download a zip file from server using CInternetSession. But i am getting incorrect size from server. My application is unicode and code as below:

    pConnection = session.GetHttpConnection((LPCTSTR)strServerName, (INTERNET_PORT)nPort);//, (LPCTSTR)NULL, (LPCTSTR)NULL);
    LPCTSTR pstrAcceptTypes = NULL;
    LPCTSTR pstrVersion = NULL;

    // Open and send the request
    pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, &pstrAcceptTypes, pstrVersion, HttpRequestFlags);

              pHttpFile->AddRequestHeaders(szHeaders);
        pHttpFile->AddRequestHeaders(\_T("User-Agent: GetWebFile/1.0\\r\\n"), HTTP\_ADDREQ\_FLAG\_ADD\_IF\_NEW);
        pHttpFile->SendRequest();
    
        pHttpFile->QueryInfoStatusCode(dwRet);//getting 200
    
        int nFileLen = pFile->GetLength(); //getting 7
    

    why I am getting incorrect size? Anything wrong in this code? Same code was working with ANSI build and not working with unicode build.

    modified on Thursday, January 13, 2011 5:43 AM

    K L C 3 Replies Last reply
    0
    • J john5632

      Hi, I am trying to download a zip file from server using CInternetSession. But i am getting incorrect size from server. My application is unicode and code as below:

      pConnection = session.GetHttpConnection((LPCTSTR)strServerName, (INTERNET_PORT)nPort);//, (LPCTSTR)NULL, (LPCTSTR)NULL);
      LPCTSTR pstrAcceptTypes = NULL;
      LPCTSTR pstrVersion = NULL;

      // Open and send the request
      pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, &pstrAcceptTypes, pstrVersion, HttpRequestFlags);

                pHttpFile->AddRequestHeaders(szHeaders);
          pHttpFile->AddRequestHeaders(\_T("User-Agent: GetWebFile/1.0\\r\\n"), HTTP\_ADDREQ\_FLAG\_ADD\_IF\_NEW);
          pHttpFile->SendRequest();
      
          pHttpFile->QueryInfoStatusCode(dwRet);//getting 200
      
          int nFileLen = pFile->GetLength(); //getting 7
      

      why I am getting incorrect size? Anything wrong in this code? Same code was working with ANSI build and not working with unicode build.

      modified on Thursday, January 13, 2011 5:43 AM

      K Offline
      K Offline
      KingsGambit
      wrote on last edited by
      #2

      I think you can try the function URLDownloadToFile(). http://msdn.microsoft.com/en-us/library/ms775123(v=vs.85).aspx[^]

      1 Reply Last reply
      0
      • J john5632

        Hi, I am trying to download a zip file from server using CInternetSession. But i am getting incorrect size from server. My application is unicode and code as below:

        pConnection = session.GetHttpConnection((LPCTSTR)strServerName, (INTERNET_PORT)nPort);//, (LPCTSTR)NULL, (LPCTSTR)NULL);
        LPCTSTR pstrAcceptTypes = NULL;
        LPCTSTR pstrVersion = NULL;

        // Open and send the request
        pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, &pstrAcceptTypes, pstrVersion, HttpRequestFlags);

                  pHttpFile->AddRequestHeaders(szHeaders);
            pHttpFile->AddRequestHeaders(\_T("User-Agent: GetWebFile/1.0\\r\\n"), HTTP\_ADDREQ\_FLAG\_ADD\_IF\_NEW);
            pHttpFile->SendRequest();
        
            pHttpFile->QueryInfoStatusCode(dwRet);//getting 200
        
            int nFileLen = pFile->GetLength(); //getting 7
        

        why I am getting incorrect size? Anything wrong in this code? Same code was working with ANSI build and not working with unicode build.

        modified on Thursday, January 13, 2011 5:43 AM

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        john5632 wrote:

        int nFileLen = pFile->GetLength(); //getting 7

        where is pFile defined and initialised? It does not appear in this code snippet.

        I must get a clever new signature for 2011.

        J 1 Reply Last reply
        0
        • L Lost User

          john5632 wrote:

          int nFileLen = pFile->GetLength(); //getting 7

          where is pFile defined and initialised? It does not appear in this code snippet.

          I must get a clever new signature for 2011.

          J Offline
          J Offline
          john5632
          wrote on last edited by
          #4

          sorry this is

          pHttpFile->GetLength(); //getting 7

          L 1 Reply Last reply
          0
          • J john5632

            Hi, I am trying to download a zip file from server using CInternetSession. But i am getting incorrect size from server. My application is unicode and code as below:

            pConnection = session.GetHttpConnection((LPCTSTR)strServerName, (INTERNET_PORT)nPort);//, (LPCTSTR)NULL, (LPCTSTR)NULL);
            LPCTSTR pstrAcceptTypes = NULL;
            LPCTSTR pstrVersion = NULL;

            // Open and send the request
            pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, &pstrAcceptTypes, pstrVersion, HttpRequestFlags);

                      pHttpFile->AddRequestHeaders(szHeaders);
                pHttpFile->AddRequestHeaders(\_T("User-Agent: GetWebFile/1.0\\r\\n"), HTTP\_ADDREQ\_FLAG\_ADD\_IF\_NEW);
                pHttpFile->SendRequest();
            
                pHttpFile->QueryInfoStatusCode(dwRet);//getting 200
            
                int nFileLen = pFile->GetLength(); //getting 7
            

            why I am getting incorrect size? Anything wrong in this code? Same code was working with ANSI build and not working with unicode build.

            modified on Thursday, January 13, 2011 5:43 AM

            C Offline
            C Offline
            Cool_Dev
            wrote on last edited by
            #5

            Is the incorrect size comes in debug version? Please run in release mode and analyze nFileLen by means of messagebox or some thing else.

            1 Reply Last reply
            0
            • J john5632

              sorry this is

              pHttpFile->GetLength(); //getting 7

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Sorry, no idea, but maybe you should be looking at the information returned from your server. [edit]Google found this[^], it may help.[/edit]

              I must get a clever new signature for 2011.

              J 1 Reply Last reply
              0
              • L Lost User

                Sorry, no idea, but maybe you should be looking at the information returned from your server. [edit]Google found this[^], it may help.[/edit]

                I must get a clever new signature for 2011.

                J Offline
                J Offline
                john5632
                wrote on last edited by
                #7

                Previously code was in ANSI and working fine but now I converted it to UNICODE and getting this issue. Any problem with API to transdfr the string to server into UNOCODE format?

                L 1 Reply Last reply
                0
                • J john5632

                  Previously code was in ANSI and working fine but now I converted it to UNICODE and getting this issue. Any problem with API to transdfr the string to server into UNOCODE format?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  john5632 wrote:

                  Any problem with API to transdfr the string to server into UNOCIDE format?

                  Assuming both ends are working in Unicode there should be no problems. You need to check both ends are following the same rules.

                  I must get a clever new signature for 2011.

                  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