Mistakes + Http Client Request and Response + Caching

I made a few silly mistakes this week and as a result of this my progress had been dragged down. For example, rdbuf function actually emptied the content of the variable(works like cut and paste) and dumping the information from the variable second time would give an empty info. At first, I thought the problem of the empty content has something to do with misusage of request and response handling but apparently it’s not. Besides this, I also made some other mistakes as well like accessing null pointer(due to the replication of code and forgot to modify it) which had actually wasted a lot of time. After fixing mistakes and successfully pushing and pulling the data from the cloud storage, I went on implementing caching for the back-end. Implementing POCO caching is actually quite challenging as I actually had two technical challnege. The first challenge is to initialize the class but I had problem initializing it because I wanted to implemented it in a different way. Furthermore, it is a private constructor class so you can’t do it this way:  Poco::xxx example= Poco::xxx(value); Dr Shawn showed me another way to initalize this and it worked:

class X {
Poco::xxx example;
X() : example(value) {
int main() {
X tmp;
return 0;

I think this is extremely useful if one had to solve private constructor class problem.

Another challenge is manipulation of caching data before it expires. I thought of two ways of doing this but I think I’ll read up on “FIFOevent” first and I hope it offers a way for me to access the value of the cache data before it expires.

In short, I’m almost done with the back end rest API except for some details to be implemented soon. I’m also well aware that there might be actually minor details that I might actually  miss out but I believe integrating this with front-end would help solving this issue.

Extra note: I’m not sure if anyone would be reading this but I do really hope that these info can actually help anyone who intends to interact with another REST API using POCO library:

1) if you want to output a istringstream, use *.rdbuf()
2) if you want to copy istringstream into stringstream, POCO library actually offers a class for this and it’s called StreamCopier. Use copystream function to do this: sc.copyStream(iStr, ss);
3) Turning stringstream into string-> string=stringstream.str();

4) putting string into string stream-> stringstream<<string;

5)HTTP response and request message:

i) to add header

request .add(key, value);

ii) to add body message/binary data

sendRequest(request)<< bodymessage/binary data;


I had this problem with dropbox api that the zip file in the cloud storage was not working properly(corrupted) and I actually realized that it was because of I didn’t set the content length of my request body message.

7) to stream the file data into a string and send through http:

std::ifstream in(“test.zip”,std::ios::binary);
std::stringstream buffer;
std::string reqbody=buffer.str();

//send the file data

sendRequest(request)<< reqbody;

8) Use https class instead of http if the rest api you intend to use is https.

You may also like...

Leave a Reply