How can i download in c++ ?
Hey guys :)
I start googling for this, but i cannot find the usefull words .. so i came here .
I wana let my program download an html / php file or whatever .
( for exemple , the index.html of a site ) . How can i do that ?
Thx .
look at the libcurl library. It provides a really easy interface for dealing with HTML/FTP/etc transfers through C++ code: http://curl.haxx.se/libcurl/.
The alternative is a different library or just using sockets programming. The latter isn't actually that bad, but there's a steep learning curve with sockets programming. it's useful to know but a little bit of a bitch to initially learn. But basically you just open up a send socket to the website in question and then send the properly formatted HTML GET/POST/etc string. You can google around for the HTML request formatting specifications.
-me
The alternative is a different library or just using sockets programming. The latter isn't actually that bad, but there's a steep learning curve with sockets programming. it's useful to know but a little bit of a bitch to initially learn. But basically you just open up a send socket to the website in question and then send the properly formatted HTML GET/POST/etc string. You can google around for the HTML request formatting specifications.
-me
http://msdn.microsoft.com/workshop/networking/moniker/reference/functions/urldownloadtofile.asp
Example:
#include <urlmon.h> //Must add the urlmon.h to project or URLDownloadToFile will not work.
#pragma comment(lib, "urlmon.lib") //Must add the lib file to project or URLDownloadToFile will not work.
int main()
{
HRESULT hr = URLDownloadToFile ( NULL, "http://www.cartoonlarry.com/index.htm", "C:\\cartoonlarry.htm", 0, NULL );
return 0;
}
Hope this helps :)
Example:
#include <urlmon.h> //Must add the urlmon.h to project or URLDownloadToFile will not work.
#pragma comment(lib, "urlmon.lib") //Must add the lib file to project or URLDownloadToFile will not work.
int main()
{
HRESULT hr = URLDownloadToFile ( NULL, "http://www.cartoonlarry.com/index.htm", "C:\\cartoonlarry.htm", 0, NULL );
return 0;
}
Hope this helps :)
Quote:Original post by ace_lovegrove
I believe you want to look into a library called WinSock.
libcurl >> Winsock =)
Winsock is the sockets programming stuff i mentioned in the latter of my 2 paragraphs.
-me
Eheh, I thought the title said 'How can I download C++'.. Had one of those, 'oh-no, not another' moments [grin] Anyway, you probably want to look into sockets, or a higher level library/wrapper if you don't want to deal with the sockets directly.
For sockets, headers etc. can be used in a more crossplatform way using SDL_net, AFAIK. (I certainly use them in my projects, so that it can run on Win/Linux/Mac OSX/FreeBSD without having to enclose #include's in #ifdef's, etc.)
thx everyone :)
Hum , i havent learned those "sokets" things again , and havent enought time ;o) atm .
I only wana do ONE task , pretty easy :) i think i can go w/o sokets :)
ill look the libcurl lib tomorow ( 23 p.m here lol) .
and about SDL_net, i may check taht too ! im using SDL§openGL in other project so im quite familliar with this :)
thx again ;)
Hum , i havent learned those "sokets" things again , and havent enought time ;o) atm .
I only wana do ONE task , pretty easy :) i think i can go w/o sokets :)
ill look the libcurl lib tomorow ( 23 p.m here lol) .
and about SDL_net, i may check taht too ! im using SDL§openGL in other project so im quite familliar with this :)
thx again ;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement