Discussion:
Intercepting internet download requests using WinInet
(too old to reply)
Albert
2004-05-06 08:21:02 UTC
Permalink
WinInet experts

I am in the process of writing a sample application that intercepts file download requests when a user selects to download a file from the Internet (yes another one). I have successfully implemented a custom IE Download Manager by implementing the IDownloadManager COM interface etc. but I suspect that there may be another approach to intercepting HTTP and FTP file requests with WinInet that may be better suited to what I need

Because I’m unfamiliar with WinInet I was hoping that you would be able to
a) Give me an indication if intercepting client file requests is at all possible with WinInet. (Comments on inter-application issues and welcome)

b) Point me at some documentation. Have not been able to get anything from the MSDN documentation so far except a good reference for methods, interfaces etc. but then again I am unfamiliar with the API so I may be missing things in there

c) If you happen to know exactly how to do it and coincidently have some sample code for this, well, that would be just fantastic. :

Thanks
Albert
Paul Baker [MVP, Windows - SDK]
2004-05-06 13:26:52 UTC
Permalink
WinInet is just an HTTP, FTP, gopher client that Internet Explorer uses. To
intercept an Internet Explorer download, you must write a Custom Download
Manager, just as you are doing. Details are here:

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/ext/overview/downloadmgr.asp

Are you intending to intercept a download from any application that uses
WinInet? I don't see how this is realstically possible.

What's the problem with using a Custom Download Manager?

Paul
WinInet experts,
I am in the process of writing a sample application that intercepts file
download requests when a user selects to download a file from the Internet
(yes another one). I have successfully implemented a custom IE Download
Manager by implementing the IDownloadManager COM interface etc. but I
suspect that there may be another approach to intercepting HTTP and FTP file
requests with WinInet that may be better suited to what I need.
Because I'm unfamiliar with WinInet I was hoping that you would be able
a) Give me an indication if intercepting client file requests is at all
possible with WinInet. (Comments on inter-application issues and welcome).
b) Point me at some documentation. Have not been able to get anything from
the MSDN documentation so far except a good reference for methods,
interfaces etc. but then again I am unfamiliar with the API so I may be
missing things in there.
c) If you happen to know exactly how to do it and coincidently have some
sample code for this, well, that would be just fantastic. :)
Thanks,
Albert.
Paul Baker [MVP, Windows - SDK]
2004-05-06 15:10:00 UTC
Permalink
Albert,

I'm sorry, I don't think I know enough about Internet Explorer to help you,
but I'll try. I would recommend working through this problem instead of
looking for an alternative. I assure you it will be the simplest way forward
in the long run!

What does "selects a download link and the URL resolves to the actual file"
mean?

What does "if the link is actually a redirect to the file to download" mean?

What I'm getting at is, are you talking about a link to a file:// URL? A
link to a http:// URL with a redirection response containing a file:// URL?
The file name of cache entry? What?

Paul
Thanks for your response Paul.
Here is a brief summary of my "hurdle" with the IDownloadManager
implementation.
When a user selects a download link and the URL resolves to the actual
file to download I have no problem retrieving the complete URL from the
IMoniker::GetDisplayName method but.if the link is actually a redirect to
- Internet Explorer displays the "Open / Save" dialog that prompts the
user if they wish to open or save the file (not to concerned about this
since I assume I would be able to change a configuration value somewhere to
make this go away)
-Then regardless of if the user selects Open or Save my IDownloadManager
implementation gets called with an URL Moniker that does not seem to point
to the file to be downloaded but rather it only contains part of the URL.
HRESULT Download(
IMoniker *pmk,
IBindCtx *pbc,
DWORD dwBindVerb,
LONG grfBINDF,
BINDINFO *pBindInfo,
LPCOLESTR pszHeaders,
LPCOLESTR pszRedir,
UINT uiCP
);
...the pszRedir value should contain the URL that the Moniker is
redirected to, but this parameter is empty when my implementation gets calle
d by IE for a redirected link.
What I have not mentioned here is that I am doing all of this using .NET
and C# and that I do not intend to make use of the URL Moniker methods to
download the file itself since I want to make use of the System.Net classes
in the .NET Framework to do this, so all that I really need from IE is the
complete URL to the file.
a) Should I be using something other than pszRedir to get the complete
URL? Is there another property that contains the file name?
b) Is there perhaps a marshalling problem between the COM call and my .NET
implementation for the download method that could cause the pszRedir value
to be lost as part of the interoperation for the method call?
public void Download(
UCOMIMoniker pmk,
UCOMIBindCtx pbc,
int dwBindVerb,
int grfBINDF,
int pBindInfo,
[MarshalAs(UnmanagedType.LPStr)] string pszHeaders,
[MarshalAs(UnmanagedType.LPStr)] string pszRedir,
int uiCP
)
c) Is there a bug in IE that it is not populating pszRedir correctly or
not creating the URL Moniker passed to me with the complete URL?
Thanks,
Albert
Paul Baker [MVP, Windows - SDK]
2004-05-06 18:33:22 UTC
Permalink
Albert,

How does Internet Explorer decide when to call your download manager? Does
it call it for all HTTP responses, or does it only call it for responses
that would ordinarily show the downloading file dialog?

You confused me with your use of the word "file". A web server doesn't
simply serve files. It can execute certain files instead of simply serving
them, like .ASP, and it is the response that we're talking about, not the
"file".

When HTTP makes a redirection, it sends a complete response with a status
code indicating that the resource is available elsewhere and a new URL in
the headers.

In your example, it is getting the response to "GET /someproduct/downloads",
which is a redirection, then making another round trip to the server to get
a response to "GET /someproduct/downloads/somefile.zip". If it is calling
your download manager for the first response, you can ignore it and continue
to the second response (which is why I ask when it is called).

Honestly, I have no clue what pszRedir is. It's not very well documented.

Paul
Much appreciated, lets try and solve this mystery. :)
What does "selects a download link and the URL resolves to the actual
file" mean?
I mean that if the user selects a HTTP URL link on a web page that
directly points to the file that the user wants to download, say
"http://www.microsoft.com/someproduct/urgentpatches/patch101.exe" for
example, then IE calls my Download method and I call the
IMoniker::GetDisplayName method that in turn returns me the complete URL
"http://www.microsoft.com/someproduct/urgentpatches/patch101.exe" that I can
use to retrieve the file from the server.
What does "if the link is actually a redirect to the file to download" mean?
I mean that the user selects a HTTP URL link on a web page that do not
directly point to the file that the user wants to download, say
"http://www.microsoft.com/someproduct/downloads", then the HTTP server that
handles the request redirects the request to say
"http://www.microsoft.com/someproduct/downloads/somefile.zip". In this
scenario, when IE calls my Download method and I call the GetDisplayName
method then I get the incomplete URL
"http://www.microsoft.com/someproduct/downloads" back from the method call
instead of the URL
"http://www.microsoft.com/someproduct/downloads/somefile.zip" that I need to
actually download the file.

Continue reading on narkive:
Search results for 'Intercepting internet download requests using WinInet' (Questions and Answers)
5
replies
how to access Internet throw mobile phone to PC? pls tell me names of mobiles?
started 2007-03-13 04:14:49 UTC
internet
Loading...