- Home /
WebGl build with WWW POST data is blank on the server
My unity game uses a WWW to POST data to a PHP server. When I run the game from the editor, all is fine. However, when I run the WebGL build, my server is getting blank data. Why? I'm using Unity 5.1.2f1.
1)
Dictionary header = new Dictionary();
header.Add("Access-Control-Allow-Credentials", "true");
header.Add("Access-Control-Allow-Headers", "Accept");
header.Add("Access-Control-Allow-Methods", "POST");
header.Add("Access-Control-Allow-Origin", "*");
WWW www = new WWW(_serverURL, data, header);
2)
WWWForm form = new WWWForm();
form.headers.Add("Access-Control-Allow-Credentials", "true");
form.headers.Add("Access-Control-Allow-Headers", "X-Requested-With");
form.headers.Add("Access-Control-Allow-Headers", "Content-Type");
form.headers.Add("Access-Control-Allow-Methods", "POST");
form.headers.Add("Access-Control-Allow-Origin", "*");
form.AddBinaryData("data", data);`
WWW www = new WWW(_serverURL, form);
Any ideas?
Hi, I'm having the same issue.
Have you found a solution?
Thanks!
I too am experiencing this same problem. The webserver says the POST is empty, but the WebGL build swears it's adding and sending post data...
I've tried adding CORS permissions to headers on both webserver and client. It works fine in editor, standalone, phone... just not on WebGL. Shouldn't even need CORS though, the WebGL build is hosted on the same server as the PHP API I'm calling.
Answer by hgbimonti · Sep 03, 2015 at 10:58 PM
Add the form.headers to your header first and you should be good to go:
WWWForm form = new WWWForm();
form.AddField("name", playerName);
Dictionary header = new Dictionary();
header = form.headers;
header.Add("Access-Control-Allow-Credentials", "true");
header.Add("Access-Control-Allow-Headers", "Accept");
header.Add("Access-Control-Allow-Methods", "POST");
header.Add("Access-Control-Allow-Origin", "*");
WWW www = new WWW(_serverURL, form.data, header);