mardi 29 janvier 2019

Set the request body while calling the API with C++Rest SDK

I'm want to call the Face API of Microsoft Computer Vision to post a picture with the C++Rest SDK. I have succeed with GET method but I don't know what to do with POST method. I have figure it out that the problem is in "request.set_body" method. I want to use it in two ways, one is posting a picture from my computer, another is posting a picture from a link of the website. If anyone knows about this problem, please help me. Thank you.

Here is the link of Face API: https://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236 And here is the code. In this code, I try to post a picture from a website:

{
    http_client client(U("https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect"));

    http_request request(methods::POST);
    request.headers().set_content_type(L"application/json");

    uri_builder builder;
    // Append the query parameters: [?returnFaceId][&returnFaceLandmarks]
    builder.append_query(U("returnFaceId"), U("true"));
    builder.append_query(U("returnFaceLandmarks"), U("false"));
    builder.append_query(U("subscription-key"), U("*********************"));

    web::json::value requestParameters;
    requestParameters[U("bar")] = web::json::value::object(U("https://cdn.explus.vn/media.phunutoday.vn/files/upload_images/2016/02/02/my-tam-cam-ngan-mo-5-phunutoday_vn.jpg"));

    utility::stringstream_t paramStream;
    requestParameters.serialize(paramStream);

    request.set_body(paramStream.str());
    request.set_request_uri(builder.to_uri());

    auto path_query_fragment = builder.to_string();

    // Make an HTTP GET request and asynchronously process the response
    return client.request(request).then([](http_response response)

Aucun commentaire:

Enregistrer un commentaire