【问题标题】:Http upload with progress info, in C++ (Poco/Boost)带有进度信息的 Http 上传,使用 C++ (Poco/Boost)
【发布时间】:2012-02-13 11:54:21
【问题描述】:

我正在尝试将一个大文件上传到我的 http 服务器。

我需要显示上传进度。

如何获取上传期间发送了多少字节?

需要向我的 GUI 发送事件。

在 poco 中,我不知道把回调放在哪里。

_session.sendRequest(_request)
_session.receiveResponse(_response)

有什么想法吗?或链接,谢谢!!

【问题讨论】:

    标签: c++ http boost poco-libraries


    【解决方案1】:

    这是 08 年“部分”讨论的。具有讽刺意味的是,我正在寻找完全相同的东西。

    http://sourceforge.net/mailarchive/message.php?msg_id=20619477


    编辑:2012 年 2 月 14 日

    这不是最好的,但它可以工作......可能最好一次写入 1k 个块。 我想看看你的建议。

    std::string szMessage;
    .... /* fill your szMessage such as with a Form.write()  */ .. 
    
    CountingOutputStream _cos( _session.sendRequest(_request) )    
    std::streamsize len = 0;
    
    string::iterator it;
    for ( it=szMessage.begin() ; it < szMessage.end(); it++ ) {
         len ++;
         _cos.put(*it);
         if(len %4096 ==0)
                cout << "len: " << len << endl;
    }
    cout << "Chars printed: " << len << endl;
    
    std::istream& rsout = _session.receiveResponse(_response)
    std::ostringstream ostr;
    StreamCopier::copyStream(rsout, ostr);
    //    Retrieve response is not necessary if we have the resp code
    std::cout << endl; response.write(cout);
    std::cout << ostr.str();
    int code = response.getStatus();
    if (code != nRespCode) {
       stringstream s;
       s << "HTTP Error(*): " << code;
       throw Poco::IOException(s.str());
    }
    

    【讨论】:

    • 我认为这不是很优雅。但它有效。我会把它放在我的编辑中。谢谢!
    • 我将 char buff[HALF_MB] 作为缓冲区,并使用 content-length 或 file-size 来控制最后一个块:)
    猜你喜欢
    • 2014-11-19
    • 2015-04-09
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    • 2016-06-19
    • 1970-01-01
    • 2012-04-08
    • 2020-07-09
    相关资源
    最近更新 更多