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

2019-08-03 22:45发布

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条回答
Animai°情兽
2楼-- · 2019-08-03 23:23

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());
}
查看更多
登录 后发表回答