From a2474e4be58407773fede18a47fe0149891ee222 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Tue, 31 Mar 2020 21:15:07 +0300 Subject: [PATCH] Override request content for Post/url-encoded-body. Close #268 --- Source/VaRest/Private/VaRestRequestJSON.cpp | 28 +++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 9dd4f1dd..5089fa5f 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -355,19 +355,27 @@ void UVaRestRequestJSON::ProcessRequest() FString UrlParams = ""; uint16 ParamIdx = 0; - // Loop through all the values and prepare additional url part - for (auto RequestIt = RequestJsonObj->GetRootObject()->Values.CreateIterator(); RequestIt; ++RequestIt) + // Add optional string content + if (!StringRequestContent.IsEmpty()) { - FString Key = RequestIt.Key(); - FString Value = RequestIt.Value().Get()->AsString(); - - if (!Key.IsEmpty() && !Value.IsEmpty()) + UrlParams = StringRequestContent; + } + else + { + // Loop through all the values and prepare additional url part + for (auto RequestIt = RequestJsonObj->GetRootObject()->Values.CreateIterator(); RequestIt; ++RequestIt) { - UrlParams += ParamIdx == 0 ? "" : "&"; - UrlParams += UVaRestLibrary::PercentEncode(Key) + "=" + UVaRestLibrary::PercentEncode(Value); - } + FString Key = RequestIt.Key(); + FString Value = RequestIt.Value().Get()->AsString(); - ParamIdx++; + if (!Key.IsEmpty() && !Value.IsEmpty()) + { + UrlParams += ParamIdx == 0 ? "" : "&"; + UrlParams += UVaRestLibrary::PercentEncode(Key) + "=" + UVaRestLibrary::PercentEncode(Value); + } + + ParamIdx++; + } } // Apply params