Skip to content

Commit

Permalink
Override request content for Post/url-encoded-body. Close #268
Browse files Browse the repository at this point in the history
  • Loading branch information
ufna committed Mar 31, 2020
1 parent 9c4c896 commit a2474e4
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Source/VaRest/Private/VaRestRequestJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a2474e4

Please sign in to comment.