Trying to create HTTP Post request with binary data

Jun 26, 2014 at 10:29 PM
FYI: I am fairly new to all of this. Trying to get a grasp but need to get something functional and then I can go back and research what is really going on. Appreciate any help.

I am trying to post binary data and have a callback function upon completion.
    pplx::task<int> Post( char *postData, void *( (*returned_Data)(void *) ) )
        return pplx::create_task( [=]( char *postData )
            membuf sbuf( postData, postData + sizeof(postData) );
            std::istream in(&sbuf);

            http_client client(U(""));
            return client.request( methods::POST, L"", in, (size_t)80 );   
        }).then( [] ( http_response response )
            if ( response.status_code() == status_codes::OK )
                auto body = response.extract_vector();    
I am receiving the following error on the request: Error: No instance of overloaded function "web::http:client::http_client::request" matches the argument list
 argument types are: (const web::http::method, const wchar_t[1], std::istream, size_t )
 object type is: web::http:client::http_client
Also, I am not doing anything with the function pointer because I am not sure how to include it in the capture list.

Jul 1, 2014 at 1:48 AM
Hi Ama,

The compiler error you are receiving is correct, none of the http_client::request overload take in a std::istream. If you have the request body in a raw pointer you can use the rawptr_stream. For example here is what your code might look like, please note I removed the response body processing because I'm not sure what you want to do there.
#include <cpprest/http_client.h>
#include <cpprest/rawptrstream.h>

using namespace web::http;
using namespace web::http::client;
using namespace concurrency::streams;

pplx::task<void> Post(char *postData, size_t postDataSize)
    http_client client(U(""));
    auto inputStream = rawptr_stream<uint8_t>::open_istream(reinterpret_cast<uint8_t *>(postData), postDataSize);

    return client.request(methods::POST, L"", inputStream).then([](http_response response)
        // Headers have arrived...
        // TODO check status code, error handling, exceptions, etc....
        // If you need to handle response body data use http_response::extract_string(), 
        // http_response::extract_json(), http_response::extract_vector(), or http_response::body()
        // to get access to the raw stream.