Http upload with progress info, in C++ (Poco/Boost)

家住魔仙堡 提交于 2019-12-24 08:35:44

问题


I'm trying to upload a big file to my http server.

And i need to show a upload progress.

How can i get HOW MANY BYTES are sent during the upload?

Need send events to my GUI.

In poco, i don't know where to put the callback.

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

Any ideas? or links, Thanks!!


回答1:


This was 'partially' discussed in 08. Ironically I am looking for exactly the same thing.

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


EDIT: 02/14/12

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


来源:https://stackoverflow.com/questions/9260056/http-upload-with-progress-info-in-c-poco-boost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!