Our PPC (WinCE) MFC app is using CHHTPConnection and CHTTPFile to download a
file via HTTP. The problem is that if the file is larger than the device's
cache supports, MFC throws an error: Error: 12158:
ERROR_INTERNET_UNABLE_TO_CACHE_FILE.

Is there a way we can determine the file size of the file BEFORE we receive
this error?

Here is our current code.
NOTE: dwFlags=0. We can NOT use INTERNET_FLAG_DONT_CACHE as a flag since
WinCE does NOT allow this flag.

---------------------------------------------------------------------------------------------------------
file = connection->OpenRequest(1, strFile, NULL, 1, ppszAcceptTypes, NULL,
dwFlags);
file->AddRequestHeaders("");
file->SendRequest(); <============ This is where MFC throws the
exception

// Get file length & last modified date of file.
file->QueryInfo( HTTP_QUERY_CONTENT_LENGTH, dwLen, NULL ); <==== this is
where we would normally get the file size
---------------------------------------------------------------------------------------------------------

So my question is: What possible call(s) can we make to retrieve the file
size of the file so as to avoid the ERROR_INTERNET_UNABLE_TO_CACHE_FILE
error?

Remember:
1) This is WinCE using eVC++ 3.0
2) We can NOT use the INTERNET_FLAG_DONT_CACHE or the
INTERNET_FLAG_PRAGMA_NOCACHE flag.

My guess would be that we need to formulate some sort of request header
string, but I don't know what that would look like.

Can anyone provide any guidance?

Many thanks experts!

Re: How to fetch a file's size from a server via HTTP and request headers? by Andy

Andy
Wed Jun 01 16:28:56 CDT 2005

Not too familiar with MFC's HTTP classes but:

* INTERNET_FLAG_DONT_CACHE is supported and works at the WinInet level, the
preferred synonym for this flag is INTERNET_FLAG_NO_CACHE_WRITE
* Issue an HTTP "HEAD" instead of "GET" request to get only the headers
without the body if you need to know the content-length in advance. (Change
the first param to OpenRequest() from 1 to 2)

Andy.

"Mark Findlay" <mfindlay@speakeasy.org> wrote in message
news:exYdOe8YFHA.132@TK2MSFTNGP10.phx.gbl...
> Our PPC (WinCE) MFC app is using CHHTPConnection and CHTTPFile to download
> a file via HTTP. The problem is that if the file is larger than the
> device's cache supports, MFC throws an error: Error: 12158:
> ERROR_INTERNET_UNABLE_TO_CACHE_FILE.
>
> Is there a way we can determine the file size of the file BEFORE we
> receive this error?
>
> Here is our current code.
> NOTE: dwFlags=0. We can NOT use INTERNET_FLAG_DONT_CACHE as a flag since
> WinCE does NOT allow this flag.
>
> ---------------------------------------------------------------------------------------------------------
> file = connection->OpenRequest(1, strFile, NULL, 1, ppszAcceptTypes, NULL,
> dwFlags);
> file->AddRequestHeaders("");
> file->SendRequest(); <============ This is where MFC throws the
> exception
>
> // Get file length & last modified date of file.
> file->QueryInfo( HTTP_QUERY_CONTENT_LENGTH, dwLen, NULL ); <==== this
> is where we would normally get the file size
> ---------------------------------------------------------------------------------------------------------
>
> So my question is: What possible call(s) can we make to retrieve the file
> size of the file so as to avoid the ERROR_INTERNET_UNABLE_TO_CACHE_FILE
> error?
>
> Remember:
> 1) This is WinCE using eVC++ 3.0
> 2) We can NOT use the INTERNET_FLAG_DONT_CACHE or the
> INTERNET_FLAG_PRAGMA_NOCACHE flag.
>
> My guess would be that we need to formulate some sort of request header
> string, but I don't know what that would look like.
>
> Can anyone provide any guidance?
>
> Many thanks experts!
>