poco http下载文件为何长度不一样?文件不正确呢?

giant36 2006-06-14 12:49:59
问题:
用下边程序下载下来的文件用winrar解压时提示不正确,
但用IE下载下来是好使的


改自poco 范例:Net/samples/download
程序如下

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <ctime>
#include <Foundation/Logger.h>
#include <Foundation/PatternFormatter.h>
#include <Foundation/FormattingChannel.h>
#include <Foundation/FileChannel.h>
#include <Foundation/RegularExpression.h>
#include <Foundation/Path.h>
#include <Foundation/StreamCopier.h>
#include <Foundation/URI.h>
#include <Foundation/URIStreamOpener.h>
#include <Net/HTTPStreamFactory.h>
#include <Net/FTPStreamFactory.h>

int main(int argc, char** argv)
{
HTTPStreamFactory::registerFactory();
FTPStreamFactory::registerFactory();

if (argc != 2)
{
Path p(argv[0]);
std::cerr << "usage: " << p.getBaseName() << " <uri>" << std::endl;
std::cerr << " Download <uri> to standard output." << std::endl;
std::cerr << " Works with http, ftp and file URIs." << std::endl;
return 1;
}

try
{
URI uri("http://www.amazing3d2.com/free3d2/cleve3ds.zip");
std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open(uri));
ofstream fs("c:\\cleve3ds.zip");
if(!fs)
{
throw exception();
}
StreamCopier::copyStream(*pStr.get(), fs);
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}

return 0;
}
...全文
324 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
iambic 2006-12-23
  • 打赏
  • 举报
回复
poco是啥啊?
ReverseEngineering 2006-12-23
  • 打赏
  • 举报
回复
散分吧!
giant36 2006-06-14
  • 打赏
  • 举报
回复
问题已解决
原因在于打开保存文件时未使用二进制方式
把上边
ofstream fs("c:\\cleve3ds.zip");
改为
ofstream fs("c:\\cleve3ds.zip",ios_base::out|ios_base::trunc| ios::binary);

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧