- Home /
Unity5 WebPlayer WWWForm working only in Google Chrome
VOTE: http://issuetracker.unity3d.com/issues/www-forms-do-not-work-properly-in-webplayer-unity-5
Hello, when Unity5 has been released, the WWWForm seems to be not working.(Don't sends the fields) but only working correcly on google chrome : /
(Problem explained in code(comments))
Some code:
//C# Code:
//A method to get WWW instance with fields etc.
... WWW GetWeb(string message)
{
WWWForm form = new WWWForm();
string msg = /*encrypt message*/ .Trim();
form.AddField("input", msg);
WWW web = new WWW(/*the url*/, form);
web.threadPriority = ThreadPriority.High;
return web;
}
//Download data from www:
...IEnumerator Method_Name(...)
{
var web = GetWeb("A MESSAGE HERE sth. like: operationId:value1:value2...");
yield return web;
Debug.Log(web.error); //Log "Null"
Debug.Log(web.text); //Log "ENCRYPTED MESSAGE"
Debug.Log(/*decrypt: web.text*/); //Log: "> ERROR" It isn't excepted : [
}
//PHP Code:
...
if(empty($_POST['input']))
Die(encrypt("> ERROR")); // The problem: $_POST['input'] is empty : /
...
Thanks in advance, Erdroy.
Did you get any confirmation that this is a real bug and that someone is working on it ?
Has anyone found a work-around yet? I urgently need a solution to solve this issue.
Blazerker try this:
Add one binary field to your WWWForm:
wwwForm.AddBinaryData("binary", new byte[1]);
For me it works.
I have tried that - it didn't work. When adding it there's an error submitting the form and it doesn't communicate at all.
Answer by MariuszKowalczyk · Apr 02, 2015 at 11:19 PM
Workaround:
Add one binary field to your WWWForm:
wwwForm.AddBinaryData("binary", new byte[1]);
Now everything will work.
doesn't work either, tried it with Unity 5.0.0f4 & 5.0.1f1.. what's taking so long for the Unity Team to fix this???
This issue was fixed, it should be available in 5.01p1 i was told
it's not since I downloaded it yesterday and did 4 hours of testing to no avail. Same exact code works fine when I publish on 4.6 from another system
5.0.1 Patch 1, it's not out yet. should be in a few days probably
5.0.1 Patch 1 - this release is not out yet (probably in a few days)
Answer by clever · Apr 23, 2015 at 02:42 PM
So 5.0.1p1 "may" have fixed the issue, sadly the game doesn't load on webplayer. AND now Chrome stopped support for Unity WebPlayer so we're up sh-t creek without a paddle.. really depressing
Answer by Gselivanof · Mar 08, 2015 at 08:20 PM
Check your other browser UnityWeb player and Java Plug-in. If it doesn't help send me back.
Firefox and IE doesn't work... Only Google Chrome works. But, it's a some type of bug/issue I think. http://issuetracker.unity3d.com/issues/www-post-request-on-webplayer-built-by-unity-5-dot-0-0f2-creates-an-invalid-request
Answer by Blazerker · Apr 24, 2015 at 01:30 PM
This workaround worked for me...
In PHP
if (empty($_POST))
{
$data = file_get_contents('php://input');
$data = substr($data,strrpos($data,"\n"));
$vars = explode("&",$data);
$_POST = array();
for ($i = 0; $i < count($vars); $i++)
{
list($key, $value) = split("=", $vars[$i],2);
if(strlen(trim($key))>0)
{
$key=preg_replace('/[\n\r]/', '', $key);
$value=preg_replace('/[\n\r]/', '', $value);
$_POST[$key]=$value;
}
}
}
Update:
The above code works in Firefox, but not in Safari. It seems the raw data is intact and identical in both, but the way the $_POST variable is formed seems to differ between the two. The only thing I know of that recently changed is the release of PHP 5.6 and I have a hunch it has something to do with $HTTP_RAW_POST_DATA and always_populate_raw_post_data being depreciated... Maybe someone with more knowledge of this can verify...
By forcing php to always interpret php://input and omitting the if(empty($_POST)) statement seems to fix the bug, but I still need to test it from mobile compilations.
$data = file_get_contents('php://input');
$data = substr($data,strrpos($data,"\n"));
$vars = explode("&",$data);
$_POST = array();
for ($i = 0; $i < count($vars); $i++)
{
list($key, $value) = split("=", $vars[$i],2);
if(strlen(trim($key))>0)
{
$key=preg_replace('/[\n\r]/', '', $key);
$value=preg_replace('/[\n\r]/', '', $value);
$_POST[$key]=$value;
}
}