0

Possible Duplicate:
How to download a file with WinHTTP in C/C++?

I have a URL, example:

https://dl.dropbox.com/u/5465642/myfile.xml

And a C++ application on Windows. When my application launches I want to spend 2 seconds to try to download the file into application memory. If file is downloaded I will do my stuff with it. If not I will just skip it. I don't want to use C# and .Net for this. No heavy external libraries or DLLs. Probably WinApi or some small external library. To work on Windows XP and higher. Not dependent of IE explorer version or something similar.

Community
  • 1
  • 1
Dmitriy
  • 5,357
  • 8
  • 45
  • 57
  • 1
    Where are you stuck? Sockets, SSL, HTTP? – mfontanini Nov 12 '12 at 20:06
  • Import the msxml6 library. It ships with (vista maybe? win7 for sure and up) and is installible on XP. Initiate COM and the create an IXMLHTTPRequest object and send a request. Much easier than WinHttp libraries and juggling certs. https://msdn.microsoft.com/en-us/library/ms759148(v=vs.85).aspx – jmucchiello Dec 09 '16 at 00:43

1 Answers1

0

Get the IP of the host, open a socket, connect to the IP, do the SSL/TLS handshake, do the fetch, close the socket. For the handshake, you use AcquireCredentialsHandle, InitializeSecurityContext, QueryContextAttributes, CertVerifyTimeValidity, etc. For sending you'll use EncryptMessage. For receiving you'll use DecryptMessage. Search for Microsoft examples using those APIs and you'll be fine. Manage your own recv timeouts during the handshake and receive to handle your timeout.

mark
  • 5,269
  • 2
  • 21
  • 34