Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SaintGrey · Aug 04, 2015 at 02:38 PM · buildwebglwwwpost

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?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hgbimonti · Aug 31, 2015 at 07:49 PM 0
Share

Hi, I'm having the same issue.

Have you found a solution?

Thanks!

avatar image vanmani · Jul 12, 2016 at 01:53 AM 0
Share

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.

avatar image hgbimonti · Jul 12, 2016 at 09:55 PM 0
Share

@vanmani, check my reply below.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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);



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by 8Observer8 · Dec 29, 2015 at 10:08 PM

http://forum.unity3d.com/threads/webgl-and-mysql.376556/#post-2442675

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

How to Upload multiple files to a server using UnityWebRequest.Post(); 3 Answers

How to profile a WebGL app using the unity profiler tool? 0 Answers

How to feature WebGL build on SquareSpace? 1 Answer

when build to webGL 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges