- Home /
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);
}
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?
Edited again, apparently there was an other error. However it didn't give me any errors
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.
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.
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...
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613124241im_/https://answers.unity.com/themes/thub/images/avi.jpg)