I am writing an HTTP client in C++ with Poco and there is a situation in which the server sends a response with a jpeg image content (in bytes). I need the client to process the response and generate a jpg image file from those bytes.
I searched the Poco library for appropriate functions but I haven't found any. It seems that the only way to do it is manually.
This is part of my code. It takes the response and makes the input stream start at the beginning of the image content.
/* Get response */
HTTPResponse res;
cout << res.getStatus() << " " << res.getReason() << endl;
istream &is = session.receiveResponse(res);
/* Download the image from the server */
char *s = NULL;
int length;
std::string slength;
for (;;) {
is.getline(s, '\n');
string line(s);
if (line.find("Content-Length:") < 0)
continue;
slength = line.substr(15);
slength = trim(slength);
stringstream(slength) >> length;
break;
}
/* Make `is` point to the beginning of the image content */
is.getline(s, '\n');
How to proceed?