Can I handle streams with http_client?

Aug 14, 2014 at 3:57 PM
By "streams" I mean something like mjpeg.
Actualy I have tied to write some code:
http_client client(host);
            
uri_builder builder(L"/"+path + m_File);
container_buffer<std::string> buffer;

client.request(methods::GET, builder.to_string(), cancellationTokenSource.get_token()).then([this, buffer](http_response response)
{
    OutputDebugString((L"Received response status code: " + NumToStr(response.status_code()) + L"\n").c_str());
}).then([this, buffer](/*streams::istream stream*/task<void>prevTask)
{
    try {
        prevTask.get();
    }
    catch (Platform::Exception^ ex)
    {
        OutputDebugString(ex->Message->Data());
    }
    catch (std::exception ex)
    {
        string message(ex.what());
        OutputDebugString(string2wstring(message).c_str());
    }
}); 
And it work perfect with static images, but when I try to feed mjpeg link - I got "Unknown exception". So question is: Does current implementaion of SDK supports such cases?
Thanks
Aug 14, 2014 at 4:22 PM
Sorry, I think I rushed. Guess this exception was raised because of lack of credentials
Coordinator
Aug 14, 2014 at 4:38 PM
Hi Daemonolog,

Exception authentication issues aside I assume what you are referring to is getting the HTTP response body through a stream as the chunks come across the network. Yes this is possible with the C++ Rest SDK. The task returned from http_client::request is signaled once all the HTTP headers have arrived. You can then call http_response::body() to get access to the underlying stream for the response body. I believe this should be what you are looking for.

Steve
Aug 14, 2014 at 5:19 PM
Yes, this is what I looked for. Thank you