Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Darcar90 · Dec 15, 2013 at 11:51 PM · wwwphphighscorescrossdomain

WWW Post doesn't work.

Hi all, I'm trting to make an highscore table but I found some problems... I followed this guide to set up one using javascript and php for the server. The connection are all fine, i can even display the scores I have put in for test but I could not store any scores via WWW, I have tried also WWWForm [with WWW(url,form)] for a more specific post request but it didn't work neither... The funny thing is that if I use Application.OpenURL(http://url.php?id=...&value=...) it works perfectly but it open a browser every time.

Do you have any ideas how can OpenURL works and WWW doesn't?

EDIT:

Yes, I had build it for the webplayer but I placed the crossdomain.xml in the root of the webserver.

 <?xml version="1.0"?>
 <cross-domain-policy>
 <allow-access-from domain="*"/>
 </cross-domain-policy>

Tried to switch platfotm and it works, so it' actually a crossdomain problem, but the problem persist, why can I GET information but I can't POST anyone, can it be a sockets problem?

PS: crossdomain.xml and the unity web player are in the same (web) folder

LAST EDIT:

Now that's quite funny, apparently i found a solution, this was my code:

 if (press button) {
 
     postScore(var, var);
     application.Loadlevel("Other_scene");
 
 }
 

I tried removing LoadLevel and all worked fine! It's possible that changing scene I didn't give enough time to complete postScore()? If that's corret what does the yield in the postScore() function?

 hs_post = WWW(highscore_url);
     yield hs_post; // Why it doesn't really wait?   
     if(hs_post.error) {
         print("There was an error posting the high score: " + hs_post.error);
     }

Comment
Add comment · Show 4
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 Bunny83 · Dec 16, 2013 at 11:17 AM 0
Share

There's no difference between a GET or POST request when it comes to security. You're giving us a hard time to help you. The example sends the score also with a GET request. When retrieving of data works, sending should as well. Are you sure your URLs are right?

$$anonymous$$eep in $$anonymous$$d that URL path and filenames are case-sensitive.

BTW: What does "doesn't work" mean? Do you get any errors? If you do any kind of http request you always get any kind of "reaction". Have you checked www.error? Any exceptions?

avatar image Darcar90 · Dec 16, 2013 at 02:18 PM 0
Share

Edited again, apparently there was an other error. However it didn't give me any errors

avatar image Bunny83 · Dec 16, 2013 at 02:42 PM 0
Share

Of course, when you change the level all your objects get destroyed which includes your coroutine (a coroutine is actually an object, not a function).

Did you use DontDestroyOnLoad on the object? if not it will be wiped out when the new scene loads.

avatar image Darcar90 · Dec 16, 2013 at 05:25 PM 0
Share

Now it'a all clear, ty for the help!

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Dec 16, 2013 at 12:41 AM

Well, i can tell you that post requests work pretty well. In my former company we build games for web and android / iOS and had a lot server communication mostly via post requests. If something "doesn't work" you probably doing something wrong. Since you didn't included any concrete code snippets we can't tell you what you're doing wrong.

However just in case you build for the webplayer and your testing in the editor, you might run into crossdomain issues due to the security sandbox of the webplayer.

If you expect any further help on this, you should edit your question and include some actual code and tell us what's your target platform.

Comment
Add comment · Show 1 · 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 Darcar90 · Dec 16, 2013 at 11:03 AM 0
Share

Edited, thank you for the quick reply! Since seems not to be a javascript of a php error I didn't put any other code (however it's copy/pasted from the tutorial). I'd put an editor but the one in ...\Temp\UnityWebPlayer\log doesn't help so much...

avatar image
1

Answer by mole1984 · Sep 03, 2015 at 01:46 AM

I found the solution!

For Android it is important that you add "http://" in WWW.

  //Not correct: 
  string post_url = "http://www.testdomain.de/display.php";
  WWW hs_post = new WWW(post_url);
  
  //correct: 
  string post_url = "www.testdomain.de/display.php";
  WWW hs_post = new WWW("http://"+post_url);

In my example you must not add the "http://" to the string, because the WWW variable hs_post will cut it. You have to add it at WWW hs_post.

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

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to send securely scores to PHP backend 2 Answers

Disable execute/write permissions on PHP files while maintaining the ability to execute them from Unity? 1 Answer

Connecting Unity game to wordpress..... ? (need help :D ) 0 Answers

www request ienumerator function doesn't work 0 Answers

PHP POST through $_REQUEST with WEBBUILD 1 Answer


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