带有进度信息的Http上传,用C ++(Poco / Boost) [英] Http upload with progress info, in C++ (Poco/Boost)
问题描述
我正在尝试将一个大文件上传到我的http服务器。
I'm trying to upload a big file to my http server.
我需要显示上传进度。
如何在上传过程中收到多少BYT?
How can i get HOW MANY BYTES are sent during the upload?
需要向我的GUI发送事件。
Need send events to my GUI.
在poco中,我不知道在哪里放回调。
In poco, i don't know where to put the callback.
_session.sendRequest(_request)
_session.receiveResponse(_response)
有什么想法吗?或者链接,谢谢!!
Any ideas? or links, Thanks!!
推荐答案
这是08年部分讨论过的。具有讽刺意味的是,我正在寻找完全相同的东西。
This was 'partially' discussed in 08. Ironically I am looking for exactly the same thing.
http:// sourceforge。 net / mailarchive / message.php?msg_id = 20619477
编辑:02/14/12
02/14/12
这不是最好的,但它有效......最好一次写1k块。
我想看看你的建议。
This is not the best, but it works... probably would best to write 1k blocks at a time. I'd like to see your suggestions.
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());
}
这篇关于带有进度信息的Http上传,用C ++(Poco / Boost)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!