login about faq

I am experiencing a strange problem with the http download progress not being accurate (off by ~50%) while downloading a file from an ApiController in a MVC 4 Web API project. If I download a file from e.g. SourceForge, the receiving code works properly, so I must be related to the Web API.

At first I thought it had to do with chunked transfer encoding, but the file is not being downloaded that way and the response header contains content-length. If I download the file manually in e.g. Google Chrome the progress is detected properly.

I can't figure whether I am doing something wrong. Am I missing a header in the response or is it perhaps related to the StreamContent method?

For debugging I activated session logging in CkHttp, but that does not seem to reveal any interesting detail:

---- Sending ----
GET /api/Download?fileId=123 HTTP/1.1
Pragma: no-cache
Accept: */*
Accept-Encoding: gzip
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Language: en-us,en;q=0.5
User-Agent: Chilkat/1.0.0 (+http://www.chilkatsoft.com/ChilkatHttpUA.asp)
Host: some.host.com
Connection: Keep-Alive

---- Received ----
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 47437580
Content-Type: application/octet-stream
Expires: -1
Server: Microsoft-IIS/7.5
Content-Disposition: attachment; filename="somefile.zip"
X-AspNet-Version: 4.0.30319
X-Content-Type-Options: nosniff
Date: Sun, 09 Dec 2012 15:59:19 GMT

The receiving code is a C++ project and the code looks similar to this:

CkHttp http;
MyHttpProgress progress(pDlg);
http.put_HeartbeatMs(100);
http.put_EventCallbackObject(&progress);
http.SetRequestHeader("Pragma","no-cache");
http.put_UseIEProxy(true);
success = http.Download("url", "destination file");

The sending code is the web api project and the code looks similar to this:

public HttpResponseMessage Get(int fileId)
{
     ...
     MemoryStream responseStream = new MemoryStream();
     Stream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read);
     fileStream.CopyTo(responseStream);
     fileStream.Close();
     responseStream.Position = 0;

     HttpResponseMessage response = new HttpResponseMessage();
     response.StatusCode = HttpStatusCode.OK;
     response.Content = new StreamContent(responseStream);
     response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
     response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
     response.Content.Headers.ContentDisposition.FileName = filename;
     response.Content.Headers.ContentLength = responseStream.Length;
     return response;
}

asked Dec 09 '12 at 11:32

roan98dk's gravatar image

roan98dk
326192034

edited Dec 10 '12 at 10:47

I forgot to mention that ReceiveRate's byteCount and bytesPerSec appears to be working fine.

(Dec 10 '12 at 09:21) roan98dk

I've performed a number of tests, but everything seems to be working fine for me. Please post the contents of the LastErrorText captured after calling Download.

(Dec 10 '12 at 11:36) chilkat ♦♦

Oh yes, I tend to forget that lastErrorText is not empty on success :)

(Dec 10 '12 at 12:31) roan98dk

Version 9.4.0 was released today, and it includes this fix. See http://www.chilkatsoft.com/downloads_vcpp.asp

link

answered Dec 13 '12 at 08:56

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

link

answered Dec 10 '12 at 17:29

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Nice work :) I will test it asap.

(Dec 10 '12 at 17:41) roan98dk

Does this build also include the fixes for SynchronousRequest vs. http status code 204 as mentioned in another thread?

(Dec 10 '12 at 18:53) roan98dk

Well there is "sort of" a new problem. You apparently made other unrelated changes to other components:

CkZipEntry::inflateToString2() no longer exists. CkZip::AppendFiles does not take 3 arguments CkZip::Extract does not take 2 arguments CkZip::WriteZipAndClose does not take 1 arguments

I guess that eventCallbacks are handled in a different way now.

(Dec 10 '12 at 19:09) roan98dk

inflateToString2 appears to have been replaced by unzipToString, but what should be specified for lineEndingBehavior?

(Dec 11 '12 at 06:02) roan98dk

I tested the prerelease and it seems to solve this problem.

(Dec 11 '12 at 13:36) roan98dk

This is the result of the non-working download (some information has been left out):

ChilkatLog:
  Download:
    DllDate: Aug 28 2012
    UnlockPrefix: XXXXXXXXXXX
    Username: XXXXXX:XXXXXX
    Architecture: Little Endian; 32-bit
    Language: Visual C++ 11.0
    VerboseLogging: 0
    backgroundThread: 0
    url: https://some.host.com/api/Download?fileId=123
    toLocalPath: D:\test\test.zip
    RegistryQueryError: The system cannot find the file specified.
    ValueName: ProxyServer
    Failed to get key value
    valueName: ProxyServer
    Failed to read registry: CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/ProxyServer
    localFileAlreadyExists: 0
    QuickGetToOutput_Download:
      qGet_1:
        simpleHttpRequest_3:
          httpMethod: GET
          requestUrl: https://some.host.com/api/Download?fileId=123
          RegistryQueryError: The system cannot find the file specified.
          ValueName: ProxyServer
          Failed to get key value
          valueName: ProxyServer
          Failed to read registry: CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/ProxyServer
          Connecting to web server...
          httpServer: some.host.com
          port: 443
          Using HTTPS.
          ConnectTimeoutMs_1: 10000
          Multi-threaded hostname to IP address resolution
          Resolving domain name (IPV4/IPV6)...
          AddrInfoList:
            AddrInfo:
              ai_flags: 0
              ai_family: 2
              ai_socktype: 1
              ai_protocol: 0
              ai_addrlen: 16
              ai_canonname: (NULL)
            --AddrInfo
          --AddrInfoList
          Connecting to IPV4 address.
          ipAddress2: <my server ip>
          myIP_5: <my local ip>
          myPort_5: 55259
          connect successful (3)
          clientHelloMajorMinorVersion: 3.1
          buildClientHello:
            majorVersion: 3
            minorVersion: 1
            numRandomBytes: 32
            sessionIdSize: 0
            numCipherSuites: 10
            numCompressionMethods: 1
          --buildClientHello
          handshakeMessageType: ServerHello
          handshakeMessageLen: 0x46
          processHandshakeMessage:
            MessageType: ServerHello
            Processing ServerHello...
            ServerHello:
              MajorVersion: 3
              MinorVersion: 1
              SessionIdLen: 32
              CipherSuite: RSA_WITH_AES_128_CBC_SHA
              CipherSuite: 00,2f
              CompressionMethod: 0
              Queueing ServerHello message.
              ServerHello is OK.
            --ServerHello
          --processHandshakeMessage
          handshakeMessageType: Certificate
          handshakeMessageLen: 0xa50
          processHandshakeMessage:
            MessageType: Certificate
            ProcessCertificates:
              Certificate:
                derSize: 1381
                certSubjectCN: *.host.com
                certSerial: 1234567890123
                certIssuerCN: Go Daddy Secure Certification Authority
              --Certificate
              Certificate:
                derSize: 1250
                certSubjectCN: Go Daddy Secure Certification Authority
                certSerial: 0301
                certIssuerCN: 
              --Certificate
              NumCertificates: 2
              Queueing Certificates message...
            --ProcessCertificates
          --processHandshakeMessage
          handshakeMessageType: ServerHelloDone
          handshakeMessageLen: 0x0
          processHandshakeMessage:
            MessageType: ServerHelloDone
            Queueing HelloDone message.
          --processHandshakeMessage
          HandshakeQueue:
            MessageType: ServerHello
            MessageType: Certificate
            MessageType: ServerHelloDone
          --HandshakeQueue
          Dequeued ServerHello message.
          Dequeued Certificate message.
          DequeuedMessageType: ServerHelloDone
          OK to ServerHelloDone!
          No client certificate required by the server.
          Encrypted pre-master secret with server certificate RSA public key is OK.
          Sending ClientKeyExchange...
          Sent ClientKeyExchange message.
          Sending ChangeCipherSpec...
          Sent ChangeCipherSpec message.
          Derived keys.
          Installed new outgoing security params.
          Sending FINISHED message..
          algorithm: aes
          keyLength: 128
          Sent FINISHED message..
          ccsProtocolType: 1
          handshakeMessageType: HandshakeFinished
          handshakeMessageLen: 0xc
          processHandshakeMessage:
            MessageType: HandshakeFinished
            FinishedMsgLen: 12
            Queueing Finished message.
          --processHandshakeMessage
          Dequeue the FINISHED message...
          Dequeued Finished message.
          Handshake completed successfully.
          Secure Channel Established.
          connectElapsedMs: 405
          -- BuildGetRequest --
          RegistryQueryError: The system cannot find the file specified.
          ValueName: ProxyServer
          Failed to get key value
          valueName: ProxyServer
          Failed to read registry: CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/ProxyServer
          Not auto-adding cookies.
          sendElapsedMs: 0
          StatusCode: 200
          StatusText: OK
          Reading response body...
          No transfer-encoding header field.
          sslContentLength: 47437580
          extraLen: 4096
          readResponseElapsedMs: 88312
        --simpleHttpRequest_3
      --qGet_1
    --QuickGetToOutput_Download
    DownloadNumBytes: 47437580
    bFileDeleted: 0
    totalElapsedMs: 88717
    ContentLength: 47437580
    Success.
  --Download
--ChilkatLog
link

answered Dec 10 '12 at 12:42

roan98dk's gravatar image

roan98dk
326192034

The only real difference between this non-working progress and the working one below, is that the non-working download is using HTTPS.

(Dec 10 '12 at 12:45) roan98dk

And here is an example of download from SourceForge that does work:

ChilkatLog:
  Download:
    DllDate: Aug 28 2012
    UnlockPrefix: XXXXXXXXXXXX
    Username: XXXXXX:XXXXXXXXX
    Architecture: Little Endian; 32-bit
    Language: Visual C++ 11.0
    VerboseLogging: 0
    backgroundThread: 0
    url: http://downloads.sourceforge.net/project/filezilla/FileZilla_Client/3.6.0.2/FileZilla_3.6.0.2_win32-setup.exe?r=http%3A%2F%2Ffilezilla-project.org%2Fdownload.php%3Ftype%3Dclient&ts=1355154267&use_mirror=garr
    toLocalPath: D:\test\test.zip
    RegistryQueryError: The system cannot find the file specified.
    ValueName: ProxyServer
    Failed to get key value
    valueName: ProxyServer
    Failed to read registry: CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/ProxyServer
    localFileAlreadyExists: 0
    QuickGetToOutput_Download:
      qGet_1:
        simpleHttpRequest_3:
          httpMethod: GET
          requestUrl: http://downloads.sourceforge.net/project/filezilla/FileZilla_Client/3.6.0.2/FileZilla_3.6.0.2_win32-setup.exe?r=http%3A%2F%2Ffilezilla-project.org%2Fdownload.php%3Ftype%3Dclient&ts=1355154267&use_mirror=garr
          RegistryQueryError: The system cannot find the file specified.
          ValueName: ProxyServer
          Failed to get key value
          valueName: ProxyServer
          Failed to read registry: CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/ProxyServer
          Connecting to web server...
          httpServer: downloads.sourceforge.net
          port: 80
          ConnectTimeoutMs_1: 10000
          Multi-threaded hostname to IP address resolution
          Resolving domain name (IPV4/IPV6)...
          AddrInfoList:
            AddrInfo:
              ai_flags: 0
              ai_family: 2
              ai_socktype: 1
              ai_protocol: 0
              ai_addrlen: 16
              ai_canonname: (NULL)
            --AddrInfo
          --AddrInfoList
          Connecting to IPV4 address.
          ipAddress2: 216.34.181.59
          myIP_5: <my local ip>
          myPort_5: 55244
          connect successful (3)
          connectElapsedMs: 172
          -- BuildGetRequest --
          RegistryQueryError: The system cannot find the file specified.
          ValueName: ProxyServer
          Failed to get key value
          valueName: ProxyServer
          Failed to read registry: CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/ProxyServer
          Not auto-adding cookies.
          sendElapsedMs: 0
          StatusCode: 302
          StatusText: Found
          Reading response body...
          readResponseElapsedMs: 312
          redirectUrl: http://garr.dl.sourceforge.net/project/filezilla/FileZilla_Client/3.6.0.2/FileZilla_3.6.0.2_win32-setup.exe
          newUrlLocation:
            url: http://downloads.sourceforge.net/project/filezilla/FileZilla_Client/3.6.0.2/FileZilla_3.6.0.2_win32-setup.exe?r=http%3A%2F%2Ffilezilla-project.org%2Fdownload.php%3Ftype%3Dclient&ts=1355154267&use_mirror=garr
            location: http://garr.dl.sourceforge.net/project/filezilla/FileZilla_Client/3.6.0.2/FileZilla_3.6.0.2_win32-setup.exe
            newUrlFinal: http://garr.dl.sourceforge.net/project/filezilla/FileZilla_Client/3.6.0.2/FileZilla_3.6.0.2_win32-setup.exe
          --newUrlLocation
          RedirectGet:
            QuickGetToOutput_Redirect:
              newUrl: http://garr.dl.sourceforge.net/project/filezilla/FileZilla_Client/3.6.0.2/FileZilla_3.6.0.2_win32-setup.exe
              qGet_1:
                simpleHttpRequest_3:
                  httpMethod: GET
                  requestUrl: http://garr.dl.sourceforge.net/project/filezilla/FileZilla_Client/3.6.0.2/FileZilla_3.6.0.2_win32-setup.exe
                  RegistryQueryError: The system cannot find the file specified.
                  ValueName: ProxyServer
                  Failed to get key value
                  valueName: ProxyServer
                  Failed to read registry: CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/ProxyServer
                  Using new connection...
                  httpServer: garr.dl.sourceforge.net
                  port: 80
                  ConnectTimeoutMs_1: 10000
                  Multi-threaded hostname to IP address resolution
                  Resolving domain name (IPV4/IPV6)...
                  AddrInfoList:
                    AddrInfo:
                      ai_flags: 0
                      ai_family: 2
                      ai_socktype: 1
                      ai_protocol: 0
                      ai_addrlen: 16
                      ai_canonname: (NULL)
                    --AddrInfo
                  --AddrInfoList
                  Connecting to IPV4 address.
                  ipAddress2: 193.206.140.34
                  myIP_5: <my local ip>
                  myPort_5: 55245
                  connect successful (3)
                  -- BuildGetRequest --
                  RegistryQueryError: The system cannot find the file specified.
                  ValueName: ProxyServer
                  Failed to get key value
                  valueName: ProxyServer
                  Failed to read registry: CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/ProxyServer
                  Not auto-adding cookies.
                  sendElapsedMs: 0
                  StatusCode: 200
                  StatusText: OK
                  Reading response body...
                  readResponseElapsedMs: 9500
                --simpleHttpRequest_3
              --qGet_1
            --QuickGetToOutput_Redirect
          --RedirectGet
        --simpleHttpRequest_3
      --qGet_1
    --QuickGetToOutput_Download
    DownloadNumBytes: 4702459
    bFileDeleted: 0
    totalElapsedMs: 10593
    ContentLength: 4702459
    Success.
  --Download
--ChilkatLog
link

answered Dec 10 '12 at 12:44

roan98dk's gravatar image

roan98dk
326192034

Maybe the problem has to do with SSL vs. non-SSL?

(Dec 10 '12 at 12:45) chilkat ♦♦

Yes, that's it. I just confirmed. The SSL/TLS connection causes double-counting for percent-download callbacks. I'm working on the fix..

(Dec 10 '12 at 12:49) chilkat ♦♦

Thanks, I am actually testing it right now.

(Dec 10 '12 at 12:50) roan98dk

Confirmed, if I change the download of the exact same file to HTTP, there is no problem.

(Dec 10 '12 at 12:52) roan98dk

Unfortunately for testing of a bugfix, I am using VC++ 11 that you previously mentioned was not easy to create a fix for.

(Dec 10 '12 at 12:57) roan98dk

However, over the weekend I solved that problem, so I can get a VC++ 11 fix. I did find and fix the problem, and I can do a rebuild for later today..

(Dec 10 '12 at 15:36) chilkat ♦♦
showing 5 of 6 show all

I know this might be out of scope and unsupported, but now I am getting build errors like this one:

auxiliary.obj : error LNK2019: unresolved external symbol "public: char const * __thiscall CkStringArray::getString(int)" (?getString@CkStringArray@@QAEPBDH@Z) referenced in function __catch$?WriteVectorToTextFile@CAux@@SA_NPBDAAV?$vector@V?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@V?$allocator@V?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@std@@@std@@@Z$0

The odd thing is that it is only during debug build and not even in all projects. I can't seem to find any incorrect linker settings and the only thing that I updated was the chilkat source files from version 9.3.2 to 9.4.0.

The project uses the ChilkatDbgDll.lib and if I change the reference to something fake, the compiler says that the file cannot be found, so it does not appear to be a problem related to missing libfile.

If I enable verbose linker output, it appears that other chilkat methods are linked correctly, so why not the one mentioned above:

1>        Found "public: __thiscall CkString::CkString(void)" (??0CkString@@QAE@XZ)
1>          Referenced in auxiliary.obj
1>          Referenced in IMAPSettings.obj
1>          Referenced in ViewLog.obj
1>          Loaded ChilkatDbgDll.lib(CkString.obj)
1>        Found "public: bool __thiscall CkMultiByteBase::SaveLastError(char const *)" (?SaveLastError@CkMultiByteBase@@QAE_NPBD@Z)
1>          Referenced in auxiliary.obj
1>          Referenced in BackstagePageHelp.obj
1>          Referenced in FTPSettings.obj
1>          Referenced in IMAPSettings.obj
1>          Loaded ChilkatDbgDll.lib(CkMultiByteBase.obj)
1>        Found "public: __thiscall CkStringArray::CkStringArray(void)" (??0CkStringArray@@QAE@XZ)
1>          Referenced in auxiliary.obj
1>          Referenced in ChilkatDbgDll.lib(CkString.obj)
1>          Loaded ChilkatDbgDll.lib(CkStringArray.obj)
1>        Found "public: __thiscall CkMailMan::CkMailMan(void)" (??0CkMailMan@@QAE@XZ)
1>          Referenced in auxiliary.obj
1>          Loaded ChilkatDbgDll.lib(CkMailMan.obj)
1>        Found "public: __thiscall CkEmail::CkEmail(void)" (??0CkEmail@@QAE@XZ)
1>          Referenced in auxiliary.obj
1>          Loaded ChilkatDbgDll.lib(CkEmail.obj)
1>        Found "public: class CkEmail * __thiscall CkEmailBundle::GetEmail(long)" (?GetEmail@CkEmailBundle@@QAEPAVCkEmail@@J@Z)
1>          Referenced in auxiliary.obj
1>          Loaded ChilkatDbgDll.lib(CkEmailBundle.obj)
1>        Found "public: __thiscall CkImap::CkImap(void)" (??0CkImap@@QAE@XZ)
1>          Referenced in auxiliary.obj
1>          Referenced in IMAPSettings.obj
1>          Loaded ChilkatDbgDll.lib(CkImap.obj)
1>        Found "public: __thiscall CkMailProgress::CkMailProgress(void)" (??0CkMailProgress@@QAE@XZ)
1>          Referenced in auxiliary.obj
1>          Loaded ChilkatDbgDll.lib(CkMailProgress.obj)

Do you have any suggestions?

link

answered Dec 14 '12 at 07:30

roan98dk's gravatar image

roan98dk
326192034

edited Dec 14 '12 at 07:39

I did some more testing, reverted to 9.3.2 and then it built just fine. Changed references to 9.4.0 and the build error is back. Is something missing in the 9.4.0 version of the library or have I missed something here?

(Dec 17 '12 at 07:11) roan98dk

I used dumpbin to locate the missing references in the ChilkatDbgDll.lib. I couldn't find ?getString@CkStringArray@@QAEPBDH@Z, but instead there is ?getString@CkStringArray@@QAEPBDJ@Z.

(Dec 17 '12 at 07:55) roan98dk

Perhaps I got a little closer to the problem. Out of pure curiosity I downloaded the pre-release version of 9.4.0 (http://www.chilkatsoft.com/prerelease/chilkat-9.4.0-x86-vc11.zip). When I build with that version there are no linker errors, but the moment I use the release version the linker errors appear.

(Dec 18 '12 at 05:29) roan98dk

Another detail is that I can build a release version of my project, but not the debug version, but if I comment out all references to the involved Chilkat methods, debug build just fine. Still many other Chilkat references remain and build fine.

(Dec 18 '12 at 07:58) roan98dk
1
(Dec 18 '12 at 13:57) chilkat ♦♦

Yes it did :-)

(Dec 18 '12 at 14:12) roan98dk
showing 5 of 6 show all
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×186
×33
×22
×14
×1

Asked: Dec 09 '12 at 11:32

Seen: 4,170 times

Last updated: Dec 18 '12 at 14:12

powered by OSQA