I used to use this for my old requests. Might be helpful.
I believe yours is prone to errors because you are not binding the return value to be processed (the request is async so you can’t return true or false in same function)
void AHttpActor::MakeHttpRequest(FString url, FString payload, EHTTPMethod method, EContentType contentType, bool asByte)
{
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = Http->CreateRequest();
Request->OnProcessRequestComplete().BindUObject(this, &AHttpActor::OnResponseReceivedProcess);
Request->SetURL(url);
FString action = UEnum::GetValueAsString<EHTTPMethod>(method);
Request->SetVerb("POST");
if (contentType == EContentType::JSON) {
Request->SetHeader("Content-Type", TEXT("application/json"));
} else if (contentType == EContentType::PLAINTEXT) {
Request->SetHeader("Content-Type", TEXT("text/plain"));
} else if (contentType == EContentType::TEXTHTML) {
Request->SetHeader("Content-Type", TEXT("text/html"));
}
//Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
if (asByte == true) {
uint32 size = payload.Len();
TArray<uint8> data;
data.AddUninitialized(size);
StringToBytes(payload, data.GetData() + 1, size);
Request->SetContent(data);
}
else {
Request->SetContentAsString(payload);
}
//Request->SetHeader("Content-Type", TEXT("application/json"));
Request->ProcessRequest();
}
/*Assigned function on successfull http call*/
void AHttpActor::OnResponseReceivedProcess(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
// process return
//Create a pointer to hold the json serialized data
TSharedPtr<FJsonObject> JsonObject;
//Create a reader pointer to read the json data
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
//Deserialize the json data given Reader and the actual object to deserialize
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
// process returned json information
}
}