c++ - 带有进度信息的 Http 上传,在 C++ (Poco/Boost) 中

标签 c++ http boost poco-libraries

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

我需要显示上传进度。

我怎样才能知道上传过程中发送了多少字节?

需要将事件发送到我的 GUI。

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

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

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

最佳答案

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

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


编辑:2012 年 2 月 14 日

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

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());
}

关于c++ - 带有进度信息的 Http 上传,在 C++ (Poco/Boost) 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9260056/

相关文章:

html - 将先前 HTTP 请求中的值用于 ajax 请求的更好做法是什么?

boost - Boost Shared Memory 中的结构体和向量

c++ - boost unique_ptr 删除器

c++ - 如何在 C++ 中使用 override 关键字进行多重泛型继承?

c++ - OpenMP 和 CPU 亲和性

ASP.NET - 将所有 https 请求重写为 http

jquery - allow-control-allow-origin : * present in response, 但它仍然显示错误

c++ - 如果将不正确的参数类型传递给结构初始化器列表,为什么编译器不会生成编译错误?

c++ - 计算折扣适用价格(30%、20% 和 15% 的折扣)

c++ - 将 int64_t 转换为 time_duration