Saving http_request.body() to file

Dec 4, 2014 at 6:53 AM
Edited Dec 4, 2014 at 10:49 AM
I'm trying save raw body of POST request (using http_listener),
but calling: request.body().read_to_end(stream.streambuf()).wait();
never returns;

my test code:

void processPost(http_request &request) {
auto stream = concurrency::streams::fstream::open_ostream(
    U("data.txt"),
    std::ios_base::out | std::ios_base::binary).get();

request.body().read_to_end(stream.streambuf()).wait(); // never returns
stream.close().get();
....

Interesting fact:

if i call request.extract_vector().get(), and save vector byte by byte to file - everything works fine.

edit: i'm using debian 64-bit
Coordinator
Dec 5, 2014 at 12:59 AM
Hi arekmarud,

I wrote a test similar to what you describe and indeed encounter the bug using Ubuntu 64bit debug. I've opened a bug on Codeplex to track this. For now a workaround is to use http_request::extract_vector or http_request::extract_string and then write the data to the file. I would recommend write in chunks or all at once though, byte by byte would be terribly slow.

Thanks for reporting the issue,
Steve
Feb 1 at 5:43 PM
Hi,
i'm interested in write similar code but i didn't fine enough doc about it.
In particular i made a client POST where i send a file and from server side i need to extract not only the byte but also the name of the file because i need to open a file from server side with the same name.
Could you help me?