我想使用 Poco::Net::StreamSocket 套接字从互联网下载文件。我需要一个源模板。任何人帮助我!
问问题
3350 次
2 回答
2
这段代码对我有用:
#include "Poco/URIStreamOpener.h"
#include "Poco/StreamCopier.h"
#include "Poco/Path.h"
#include "Poco/URI.h"
#include "Poco/Exception.h"
#include "Poco/Net/HTTPStreamFactory.h"
#include "Poco/Net/FTPStreamFactory.h"
#include <memory>
#include <iostream>
using Poco::URIStreamOpener;
using Poco::StreamCopier;
using Poco::Path;
using Poco::URI;
using Poco::Exception;
using Poco::Net::HTTPStreamFactory;
using Poco::Net::FTPStreamFactory;
int main(int argc, char** argv)
{
HTTPStreamFactory::registerFactory(); // Must register the HTTP factory to stream using HTTP
FTPStreamFactory::registerFactory(); // Must register the FTP factory to stream using FTP
string url = "http://somefile.mp3";
string filePath = "C:\\somefile.mp3";
// Create and open a file stream
std::ofstream fileStream;
fileStream.open(filePath, ios::out | ios::trunc | ios::binary);
// Create the URI from the URL to the file.
URI uri(url);
// Open the stream and copy the data to the file.
std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open(uri));
StreamCopier::copyStream(*pStr.get(), fileStream);
fileStream.close();
}
以上很多内容来自此处的示例代码。
于 2016-02-11T05:05:08.120 回答
0
查看Poco 网络幻灯片的第 11 页,它应该有助于您入门。
于 2012-09-30T20:31:19.940 回答