On Sun, Mar 17, 2013 at 7:08 AM, Michael Martin Moro
<
sexym...@gmail.com> wrote:
> Actually, I use 0.9.4 and sending binary data encapsulated in a std::string
> does not work for me.
>
> Here's the code I use to send a binary file to an HTTP client requesting it:
> bool SendBinaryFile(const string& filepath, Server::response& response)
> {
> ifstream file(filepath.c_str(), std::ios::binary);
>
> if (file.is_open())
> {
> long size, begin, end;
> char* raw;
>
> begin = file.tellg();
> file.seekg(0, std::ios::end);
> end = file.tellg();
> file.seekg(0, std::ios::beg);
> size = end - begin;
> raw = new char[size + 1];
> file.read(raw, size);
> file.close();
> response = Server::response::stock_reply(Server::response::ok, raw);
Here is your problem -- you're making a temporary std::string in
stock_reply. What you want to do is this instead:
std::string binary(raw, size);
response = Server::response::stock_reply(Server::response::ok, binary);