序列化PNG和发送到休息客户端
问题描述:
我发送PNG格式的图像到我的休息客户端。 但是,当我在客户端下载文件并尝试打开它时,我会收到错误。 我相信该文件的标题丢失,但我怎么能将它们添加到服务器响应?序列化PNG和发送到休息客户端
On the details of my picture i can see, that the size and so on is missing.
ifstream Stream;
Stream.open(FullFileName,std::ios::binary);
string Content, Line;
if (Stream)
{
while (getline(Stream,Line)){
Content += Line;
}
}
Stream.close();
Request::request->set_body(Content);
答
周围搜索后发现,在这一侧后post。
而我创建的Sequenze。
ifstream *Stream = new ifstream(FullFileName, std::ios::in | std::ios::binary);
std::ostringstream *oss = new ostringstream();
*oss << Stream->rdbuf();
string *Content = new string(oss->str());
Stream->close();
Request::request->set_body(*Content);
阅读二进制文件时,getline是否有意义? –
你会用什么?如果我不打开二进制阅读我的代码只读取图像的第一行。 – Cazzador
这是你的代码问题,也是我自己学习的一个问题。我认为使用带有二进制文件的getLine是没有意义的,因为“行”可能包含1个字节,或者整个文件,具体取决于它的内容。我通常阅读标题指定的大小的二进制文件,或者至少以规则大小的块来读取。然而,我不是C++方面的专家,因此您或其他人对此有所了解,我很好奇。 –