c# - UnityWebRequest sending blank data to HTTP


Keywords:c# 


Question: 

This is a sample of what I'm doing to send data to my host, however, I think it's sending blank data. For example in the "serverKeycode", I'm sending "example", but the server is receiving just "".

C#

WWWForm form = new WWWForm();
form.AddField("serverKeycode", "example");
form.AddField("username", authUsername.text);
form.AddField("password", authPassword.text);

UnityWebRequest www = UnityWebRequest.Post("http://example.com/authenticate.php", form);
yield return www.SendWebRequest();

PHP

header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Time');

$server_key = "example";
$server_auth = filter_input(INPUT_POST, 'serverKeycode');
if ($server_auth == $server_key)
{
    // do something
}
else
{
    $myJSON->returnType = 2;
    $myJSON->message = "Key: " . $server_auth; // just for checking the key
}

When returning a JSON from the PHP and printing the $message in Unity, it prints nothing.

So does it mean that Unity is not sending the data?

It used to work on my old webhost, also, if I send the POST Request through Postman, everything works fine. Do I need to allow something in the firewall?


1 Answer: 

Before calling yield return www.SendWebResquest() just add www.chunkedTransfer = false;