1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include "httpclient.h"
#ifndef MINIMAL_GPSSHELL
# include "Poco/URIStreamOpener.h"
# include "Poco/StreamCopier.h"
# include "Poco/URI.h"
# include "Poco/Exception.h"
# include "Poco/Net/HTTPStreamFactory.h"
#endif
#include <memory>
#include <iostream>
#include <fstream>
#include <string>
int gpsshell::getFileOverHttp(const std::string& url, const std::string& tempfile_name)
{
#ifndef MINIMAL_GPSSHELL
try
{
std::ofstream localFile(tempfile_name.c_str(), std::ios_base::out | std::ios_base::binary);
if (!localFile)
{
std::cerr << "Failed to open local file for writing: " << tempfile_name << std::endl;
return 1;
}
Poco::URI uri(url);
std::unique_ptr<std::istream> ptrHttpStream(Poco::URIStreamOpener::defaultOpener().open(uri));
Poco::StreamCopier::copyStream(*ptrHttpStream.get(), localFile);
}
catch (Poco::Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
#endif
return 0;
}
|