I want to download a Html page with c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I want to download a Html page with c++

how can do it with simple solution

6th Feb 2021, 9:56 PM
ali
ali - avatar
1 Answer
+ 4
Standard c++ and HTTP don't mix very well so there isn't a terribly simple solution. Networking capabilities aren't part of the ISO standards of c++. You say "download" but if you just want to write a file to the file system, .html files are just text files and those are easily written with c++'s ofstream. Some examples writing files are at: https://www.cplusplus.com/doc/tutorial/files/ and you can write HTML like any other text file. The simplest solution for writing HTML using c++ invoked through HTTP is likely running your compiled c++ program using CGI. More details are at: https://www.tutorialspoint.com/cplusplus/cpp_web_programming.htm Another option is to implement your own HTTP server using c++. This lists a few libraries that could help you do that: https://www.reddit.com/r/cpp/comments/cjj9t5/what_c_web_server_library_one_should_use_nowadays/ Other libraries will be more suitable for you if you want to make a server in c++ but I just want to share that I've tackled a related problem before. I created an HTTP server in c++ back in 2011 so my autonomous robot racing challenge simulator could make an API available for testable code. The IARRC simulator's code is available at: https://github.com/joshi1983/IARRCSim Back in 2011, I didn't see a lot of cross-platform support for HTTP so I created my own off TCP/IP. My implementation is inferior to other libraries because it isn't optimized well or fully featured. My server doesn't support compressed HTTP responses, no HTTPS support, closes TCP/IP connections after every response instead of maintaining the connection for multiple HTTP requests and responses. I didn't implement beyond very early HTTP 1.0 protocol features.
7th Feb 2021, 12:02 AM
Josh Greig
Josh Greig - avatar