How can I set HTTP POST request body?

Hi everyone, I have the following JSON that I need to attach to the HTTP POST request:

{
  "query_input": {
    "text": {
      "text": "reserve a meeting room for six people",
      "language_code": "en-US"
    }
  }
}

I tried to set the payload with that JSON with this:

Request->SetContentAsString("{\"query_input\":{\"text\":{\"language_code\":\"en - US\",\"text\":\"reserve a meeting room for six people\"}}}");

But, the response always gives me “Error 411 (Length Required); POST requests require a Content-length header”

I tried to manually set the Content-length header manually but with no effect.

What do you think would be the problem? Isn’t there a method that lets me see what’s in the Request body before sending it? In case it would be helpful, I’m trying to replicate this example: Quickstart: Interactions with the API  |  Dialogflow ES  |  Google Cloud

Thank you in advance for the help.

Have you tried set the header as well after setting the content:

Request->SetHeader(TEXT(“Content-Type”), TEXT(“application/json”));

1 Like

Yes, i set all the headers required like this:

Request->SetURL(manager->endpoint + manager->projectID + "/agent/sessions/" + manager->sessionID + ":detectIntent");
Request->SetVerb("POST");
Request->SetHeader("Authorization", Authorization.c_str());
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->SetHeader(TEXT("Accepts"), TEXT("application/json"));

I’m trying to replicate this example: Quickstart: Interactions with the API  |  Dialogflow ES  |  Google Cloud

EDIT:
There was a problem with the Authorization Header, it had a “\n” at its end that caused problems.