Downloading file

hi
how can i download file using c++ code like this tutorial that use python.
is there any alternative way to download in c++ code?
please help me…
thanks.

That code translates directly into C++ using the normal rules to translate Python to C++. Something like this:

PT(HTTPClient) http = new HTTPClient;
PT(HTTPChannel) channel = http->make_channel(True);
channel->begin_get_document(DocumentSpec("http://my.url/"));
PT(Ramfile) rf = new Ramfile;
channel->download_to_ram(rf);
PT(AsyncTask) task = new GenericAsyncTask("download", download_task, this);
task_mgr->add(task);

Of course, you don’t have to use the task manager to do the download; the important thing is just to call channel->run() every so often until it returns false, and you can do that by whatever mechanism you find convenient.

David

thanks David
how can i add HTTPClient class to my project.
where is it? i couldn’t find the header file that contains this class.i didn’t find anything in the c++ reference at the site.

Huh, that’s weird. I don’t know why it appears to be omitted from the C++ reference pages. That bears investigation.

Still, those reference pages are only auto-generated from the .h, .cxx, and .I files, which you can find in the Panda3D source code. You can read the documentation directly there; it’s pretty readable (and I find it even easier to read than the reference pages, anyway).

In the case of HTTPClient and related classes, you’ll find them defined in panda/src/downloader.

David

Thanks David
i found HTTPClient header file and added to my project but when i want to compile my project i found this error:

Error	16	fatal error C1083: Cannot open include file: 'openssl/ssl.h': No such file or directory	c:\panda3d-1.7.2-debug\built\include\opensslwrapper.h	25

i found ssl.h in the “built/include/parser-inc/openssl” so i add parser-inc folder to my project’s header search addresses.but after that i encounter many errors like these ones:

Error	1	error C2059: syntax error : 'enum [tag]'	c:\panda3d-1.7.2-debug\built\include\parser-inc\iostream	32
Error	2	error C2334: unexpected token(s) preceding '{'; skipping apparent function body	c:\panda3d-1.7.2-debug\built\include\parser-inc\iostream	32
Error	3	error C2062: type 'long' unexpected	c:\panda3d-1.7.2-debug\built\include\parser-inc\iostream	42
Error	4	error C2238: unexpected token(s) preceding ';'	c:\panda3d-1.7.2-debug\built\include\parser-inc\iostream	42
Error	5	error C2062: type 'void' unexpected	c:\panda3d-1.7.2-debug\built\include\parser-inc\iostream	54
Error	6	error C2238: unexpected token(s) preceding ';'	c:\panda3d-1.7.2-debug\built\include\parser-inc\iostream	54

what should i do?

Don’t use the ssl.h from the parser-inc folder. In fact, never include any files from that folder in your project; the files in that folder are just stub files for the interrogate parser and aren’t meant for actual development.

ssl.h is part of OpenSSL, which is one of the third-party packages we build Panda with. OpenSSL is required for HTTPClient and related files; if you have your own custom build of Panda, it is necessary for you to have located OpenSSL at the time Panda was built. makepanda will do this automatically if the third-party tools are installed properly.

I suggest you install the “Third-party Tools” zip file available on the download page and locate ssl.h in there.

David

Thanks David for your help.