我正在使用 Poco 用 C++ 编写一个 HTTP 客户端,并且存在服务器发送带有 jpeg 图像内容(以字节为单位)的响应的情况。我需要客户端处理响应并从这些字节生成 jpg 图像文件。
我在 Poco 库中搜索了适当的函数,但没有找到。似乎唯一的方法是手动。
这是我的代码的一部分。它接受响应并使输入流从图像内容的开头开始。
/* 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');
如何进行?