HTTP data format issues

Hi. I am tring to setup a basic HTTP connection between my game and localhost. The connection is working fine. But, I am receiving null at the database.

Here is the code chunk being used:

TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
Request->SetURL(TEXT("http://127.0.0.1/insertGameStats.php"));
Request->SetVerb(TEXT("POST"));
Request->SetContentAsString(CurrentRequest.TheData);

Request->OnProcessRequestComplete().BindUObject(this, &AHTTPHandlerActor::OnResponseReceived);

Here is how I set data:

  CurrentRequest.AddURLPair(param, value);
  void AddURLPair(FString param, FString value)
{
	TheData += (delim + param + "=" + value);
	delim = "&";
}

The php Script:

$con = mysql_connect($db_hostname,$db_username);

if(!$con)
{
die("Unable to Connect to MySQL: " . mysql_error());
}

$val = $_POST’val’];

mysql_select_db($db_database, $con);

$sql = “INSERT INTO testtable(value)
VALUES
(’$val’)”;

if(!mysql_query($sql, $con))
{
die('Error: ’ . mysql_error());
}

echo “1 record added to the game stats database”;

mysql_close($con);

I know that the connection is being established, because a new entry is being made in the table. But, it is all NULL.

Any help would be greatly appreciated

I am facing similar issues setting up the php script to receive the data. I keep receiving NULL at the php side. Please help.

I have been trying to setup a way to get some gameplay stats to a server(for analysis), but I’ve been running into similar issues as well. The request does reach my localhost, but not the data. My database has a bunch of rows with just the default value, and not the value I want to send. Also, I have a similar code, but I’m accessing it through blueprints. I need help!

Since you are using Json, i guess your Data is formated to be a JsonString.

Try this in your PhP Script:

and to get the variable values do this:

A Json String can look like this:

In UE4 you eventually need to escape the " with \

Thanks. That gave me a starting point. I changed my header to Request->SetHeader(“Content-Type”, “application/x-www-form-urlencoded”);
Using this, I was able to receive using the same php script.
Thanks a lot for the help.