Saving a webpage to disk using C++

前端 未结 1 422
陌清茗
陌清茗 2020-12-22 11:56

I\'ve managed to download a \"file\" from the internet with the help of wininet library, but I can\'t seem to save a \

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-22 12:50

    If your program is going to run both on windows and unix, then use cURL. Otherwise, stick with MSVC and WinINet functions http://msdn.microsoft.com/en-us/library/windows/desktop/aa385473(v=vs.85).aspx It's much easier to use in terms of the efforts required to get your program running and distributed (esp. if you're not linking your program against cUrl statically. Otherwise, you'll need to take libcurl.dll everywhere your program runs on Windows). With WinINet, you simply need to include a header and a library to use the functions.

    If you're going to use WinINet, refer to this code snippet: http://www.programmershelp.co.uk/showcode.php?e=57 Use the same code except for the while loop. Instead of reading one byte at a time, read them by chunks and write them to the output file handle.

    If you're going to use cURL, refer to this post: Download file using libcurl in C/C++

    0 讨论(0)
提交回复
热议问题