I’ve been struggling with this for ages now and just can’t figure it out.
Now it’s become a matter of it completely breaking my project so I need to sort this out.
Can someone please help me with this?
Basically, I send a lot of data in GET format (not JSON) using the POST verb and when the data arrives on the server all data is received as GET, not POST, which breaks some of my data (specifically all base64 encoded strings have a 50/50 chance of working).
Say for example I want to send a base64 encoded email, a username and a base64 encoded password the data I pass would look like this:
email=alkjsdfh==&username=billy&password=slkjd==
On the server the excessive = characters are removed so when I MD5 the value to test for authenticity the test fails because the data doesn’t match.
This is what I am doing in Unreal:
FString Cookie = ServerGlobals->GetCookie();
FString Url = ServerGlobals->WebsiteURL;
FString WFG = Category.TrimStartAndEnd();
FString ACTION = Action.TrimStartAndEnd();
UCMLData* meta = NewObject<UCMLData>(UClass::StaticClass());
meta->SetInt("uid", ServerGlobals->GetUserId());
meta->SetInt("gid", ServerGlobals->GameId);
meta->Set("action", ACTION);
FString License = ServerGlobals->License;
FString META = FString::Printf(TEXT("wfgl=%s"), *License);
for (const TPair<FString, FString>& pair : meta->Defined)
{
META = FString::Printf(TEXT("%s&%s=%s"),*META, *pair.Key, *pair.Value);
}
//Creating a request using the Http Module
FHttpRequestRef Request = FHttpModule::Get().CreateRequest();
//Binding a function that will fire when we receive a response from our request
Request->OnProcessRequestComplete().BindUObject(this, &UWpServer::OnResponseReceived);
Request->OnHeaderReceived().BindUObject(this, &UWpServer::OnHeaderRecieved);
//This is the url on which to process the request
FString URL = FString::Printf(TEXT("%s%s"), *Url, *CContentURL);
Request->SetURL(URL);
//We're sending data so set the Http method to POST
Request->SetVerb("POST");
//Tell the host that we're an unreal agent
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
Request->SetHeader(TEXT("Content-Type"), "application/json");
Request->SetHeader(TEXT("Accepts"), TEXT("application/json"));
Request->SetHeader(TEXT("Accept-Encoding"), TEXT("identity"));
//send the user id cookie along if we have it
if(Cookie != "")
Request->SetHeader(TEXT("Cookie"), Cookie);
//Use the following command to send a string value to the server
Request->SetContentAsString(META);
//Send the request
Request->ProcessRequest();
This is my main PHP code:
<?php
//ONLY do this if POST is empty
if (empty($_POST))
{
$rawPost = file_get_contents('php://input');
mb_parse_str($rawPost, $_POST);
foreach($_POST as $k => $v) {
$_REQUEST[$k] = $v;
}
}
This function is ALWAYS called and since the data came through as GET data my POST and REQUEST arrays now have invalid data for anything that contained spaces (i.e. &description=I am awesome) or any base64 encoded data (i.e. &description=alkjsdfh==)
How do I fix this? Thanks in advance