Hi All,
I'm trying to get the filesize of a file I would like to download, before doing so. I am able to download the file, that is not the issue. From what I understood from the docs and some googling is that the below should do the trick. The result though seems to be a random number, i.e. not -1 in some unsigned format, like "4.71219e+018".
void DownloadFile ( const std::string url, const fs::path file ) { // fs:: = boost::filesystem::
try {
curlpp::Cleanup cleaner;
curlpp::Easy request;
request.setOpt ( curlpp::options::Url ( url ) );
request.setOpt ( curlpp::options::FollowLocation ( true ) );
request.setOpt ( curlpp::options::Header ( true ) );
request.setOpt ( curlpp::options::NoBody ( true ) );
request.perform ( );
double s = curlpp::infos::ContentLengthDownload::get ( request );
std::cout << s << std::endl;
}
catch ( curlpp::LogicError & e ) {
std::cerr << e.what ( ) << std::endl;
}
catch ( curlpp::RuntimeError & e ) {
std::cerr << e.what ( ) << std::endl;
}
}
The header info returned is:
HTTP/1.1 200 OK
Date: Sun, 08 Sep 2013 13:12:34 GMT
Last-modified: Sun, 21 Jul 2013 10:36:54 GMT
Content-Length: 11044341
Content-Type: application/x-executable
The value of (in the above) s = 4.71219e+018
It would be much appreciated if someone could point out my error.
Obviously it's not hard to parse the header myself, but given that curlpp is so elegantly written, getting this to work the correct way should not be rocket-science.
Thank you in advance,
degski