Quantcast
Viewing all articles
Browse latest Browse all 4845

New Post: C++ REST API (POST Method) JSON Paylod -- Getting error "No content to map to Object due to end of input"

Hi , We are getting the following error message while invoking a REST API with a "POST" method . "No content to map to Object due to end of input"

The JSON payload needs to be sent something like this {"value":""abcdefgh"}

The following code is being used . Are we wrong somewhere

auto fileStream = std::make_shared<ostream>();
    pplx::task<void> requestTask = fstream::open_ostream(U("createprocdomain.txt")).then([=](ostream outFile)
    {
        *fileStream = outFile;

        //set credentials
        http_client_config config_cred;
        credentials cred = credentials(U("admin"), U("admin")); // to be parameterized admin/ admin (username/password)
        config_cred.set_credentials(cred);
        config_cred.set_validate_certificates(false);

        uri_builder builder(U("https://10.1.222.60:9440/")); // to be parametrized 
        // set path
        builder.set_path(U("PrismGateway/services/rest/v1/protection_domains")); // to be parameterized

    __  json::value postData;
        postData[U("value")] = json::value::string(U("abcdefgh"));__

        // create connection
        http_client client(builder.to_string(), config_cred);
        http_request request;
        request.set_method(U("POST")); // POST , DELETE 

        request.headers().add(U("Authorization"), U("Basic YWRtaW46YWRtaW4=")); // to be paramerized

        //postData.as_string;
        request.set_body(postData.serialize(), U("application/json"));
    //  request.set_body(utility::stringstream_t("{value:abcdefgh}"));
        return client.request(request);
    })

        .then([=](http_response response)
    {
        printf("Received response status code:%u\n", response.status_code());
        printf("Received response :%u\n", response.body());
        //int i = 

        return response.body().read_to_end(fileStream->streambuf());
    })

        // Close the file stream.
        .then([=](size_t)
    {
        return fileStream->close();
    });

    // Wait for all the outstanding I/O to complete and handle any exceptions
    try
    {
        requestTask.wait();
    }
    // catch (const std::exception &e)
    catch (http_exception &e)
    {
        printf("11");
        std::cout << e.what() << " " << e.error_code();
        printf("Error exception:%s\n", e.error_code());
    }

}

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>