I’m trying to send a json content to a php file.
The server receives the request but the $_POST array is empty.
The code to send the json data a process the http request:
bool FOnlineIdentityKadeo::Login(int32 LocalUserNum, const FOnlineAccountCredentials& AccountCredentials)
{
UE_LOG(LogNet, Verbose, TEXT("FOnlineIdentityKadeo::Login - LocalUserNum=%i AccountCredentials.Type=%s AccountCredentials.Id=%s AccountCredentials.Token=%s"), LocalUserNum, *AccountCredentials.Type, *AccountCredentials.Id, *AccountCredentials.Token);
bool bWasSuccessful = false;
if (!bHasLoginOutstanding && KadeoEndpointProtocol.Len() && KadeoEndpoint.Len() && ServerType > 0 && ClientId.Len())
{
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject);
// Sets the json data
JsonObject->SetStringField(TEXT("uemail"), *AccountCredentials.Id);
JsonObject->SetStringField(TEXT("upassword"), *AccountCredentials.Token);
JsonObject->SetNumberField(TEXT("servertype"), (double)ServerType);
JsonObject->SetStringField(TEXT("clientid"), *ClientId);
FString OutputString;
TSharedRef<TJsonWriter<TCHAR>> JsonWriter = TJsonWriterFactory<>::Create(&OutputString);
FJsonSerializer::Serialize(JsonObject.ToSharedRef(), JsonWriter);
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
HttpRequest->SetVerb(TEXT("POST"));
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
HttpRequest->SetURL(FString::Printf(TEXT("%s://%s"), *KadeoEndpointProtocol, *KadeoEndpoint));
HttpRequest->SetContentAsString(OutputString);
HttpRequest->OnProcessRequestComplete().BindRaw(this, &FOnlineIdentityKadeo::OnLoginHttpResponseReceived);
FHttpModule::Get().SetHttpTimeout(300);
if (!HttpRequest->ProcessRequest())
{
UE_LOG(LogNet, Error, TEXT("FOnlineIdentityKadeo::Login - cannot process request"));
}
...
}
The vars are
[OnlineSubsystemKadeo]
bEnabled=true
KadeoEndpointProtocol=http
KadeoEndpoint=192.168.1.107/internal/account/auth/userlogin.php
ServerType=10
ClientId=1719301132d7846bc03cea909a8ec8e801bfbf0c5094bbe818855962fe83bf26
MaxCheckElapsedTime=30;
The userlogin.php receives the request, but the $_POST array is empty.
<?php
/**
* @copyright Kadeo 2003-2016
*/
// It is necessary to sets the content type in the header since
// the ksgm requester is waiting for.
header('Content-Type: application/json');
require_once './internal/php/inc.all.php';
$email = '';
if (isset($_POST['uemail']))
$email = $_POST['uemail'];
else{
echo jsonErrorMsg(KERR_INVALIDPARAM);
exit();
}
$pswd = '';
if (isset($_POST['upassword']))
$pswd = $_POST['upassword'];
else{
echo jsonErrorMsg(KERR_INVALIDPARAM);
exit();
}
$clientId = '';
if (isset($_POST['clientid']))
$clientId = $_POST['clientid'];
else{
echo jsonErrorMsg(KERR_INVALIDPARAM);
exit();
}
$serverType = '';
if (isset($_POST['servertype']))
$serverType = $_POST['servertype'];
else{
echo jsonErrorMsg(KERR_INVALIDPARAM);
exit();
}
// Check the match between the server type and the client id
if (KAccountManager::CheckClientId($clientId, $serverType) == FALSE){
echo jsonErrorMsg(KERR_INVALIDCLIENTID);
exit();
}
// Check login information
$token = KAccountManager::CheckLogin($email, $pswd);
if ($token !== FALSE)
echo '{"Result" : "Accepted", "AuthToken" : "'.$token.'"}';
else
echo jsonErrorMsg(KERR_INVALIDLOGIN);
?>
I also received the response from the php.
void FOnlineIdentityKadeo::OnLoginHttpResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
if (bWasSuccessful && Response.IsValid() && Response->GetContentType() == TEXT("application/json"))
{
//Create a pointer to hold the json serialized data
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject);
//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))
{
FString result = JsonObject->GetStringField("Result");
if (result == TEXT("Accepted"))
{
FString authToken = JsonObject->GetStringField("AuthToken");
}
else
if (result == TEXT("Error"))
{
int32 Code = (int32)JsonObject->GetNumberField("Code");
FString Message = JsonObject->GetStringField("Message");
UE_LOG(LogOnline, Verbose, TEXT("FOnlineIdentityKadeo::OnLoginHttpResponseReceived - Request is successful ErrorCode=%i ErrorMessage=%s"), Code, *Message);
// Handle error
}
}
}
else
{
// Handle error
UE_LOG(LogOnline, Error, TEXT("FOnlineIdentityKadeo::OnLoginHttpResponseReceived - Request return bWasSuccessful=%i ContentType=%s"), bWasSuccessful, (Response.IsValid()) ? *Response->GetContentType() : TEXT(""));
}
}
Why the php server does not receive the data in the post ?
Txs for your help.
D.