- Home /
Webplayer<->Database
My game won't connect to the database when it's build into the web player. I does work when it's just an .exe.
I used WWW to connect to a .php script to find and access my database.
I HAVE the crossdomain.xml script in my root.
I HAVE my domain in the editor.
I checked everything so it is the same ( so no http and https errors )
I have no idea what i could be doing wrong and it's driving me nuts..
EDIT: I can get data from the database from the webplayer now, but i can't send any data. I use this methode to send the new data to my database ( note that this DOES work in the editor and pc version )
public static void SendScore(string name, int score)
{
string URI = "myURLisHIDDEN";
string myParameters = "name=" + name + "&score=" + score;
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
}
}
Just checked it again, but the log files are empty.
Empty?
Try to restart your unity and run your project again. There should be something inside even if it is working properly.
Are you checking the correct directory? It is run inside editor or it is built to webplayer? http://docs.unity3d.com/$$anonymous$$anual/LogFiles.html
Yes, but I'm not sure if it is able to solve this issue.
I think your problem looks like this one
I'm not sure what the headers in your code do.
That's what in my code public string POST(string url, NameValueCollection dictionary) { try { using (var client = new WebClient()) { var response = client.UploadValues(url, dictionary); return Encoding.UTF8.GetString(response); } } catch (Exception ex) { Debug.Log("Bad url: " + ex.$$anonymous$$essage); throw; } } I haven't tested the code for a while though, I think it worked before.
public string POST(string url, NameValueCollection dictionary)
{
try
{
using (var client = new WebClient())
{
var response = client.UploadValues(url, dictionary);
return Encoding.UTF8.GetString(response);
}
}
catch (Exception ex)
{
Debug.Log("Bad url: " + ex.$$anonymous$$essage);
throw;
}
}
NotSupportedException: http://www.hidden.nl/file.php at System.Net.WebRequest.GetCreator (System.String prefix) [0x00000] in :0
at System.Net.WebRequest.Create (System.Uri requestUri) [0x00000] in :0
at System.Net.WebClient.GetWebRequest (System.Uri address) [0x00000] in :0
at System.Net.WebClient.SetupRequest (System.Uri uri) [0x00000] in :0
at System.Net.WebClient.SetupRequest (System.Uri uri, System.String method, Boolean is_upload) [0x00000] in :0
at System.Net.WebClient.UploadDataCore (System.Uri address, System.String method, System.Byte[] data, System.Object userToken) [0x00000] in :0
at System.Net.WebClient.UploadData (System.Uri address, System.String method, System.Byte[] data) [0x00000] in :0 Rethrow as WebException: An error occurred perfor$$anonymous$$g a WebClient request. at System.Net.WebClient.UploadData (System.Uri address, System.String method, System.Byte[] data) [0x00000] in :0
at System.Net.WebClient.UploadData (System.Uri address, System.Byte[] data) [0x00000] in :0
at System.Net.WebClient.UploadData (System.String address, System.Byte[] data) [0x00000] in :0
at System.Net.WebClient.UploadString (System.String address, System.String data) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Net.WebClient:UploadString (string,string)
at OnlineHighScore.SendScore (System.String name, Int32 score) [0x00000] in :0
at GameOver.OnGUI () [0x00000] in :0
(Filename: Line: -1)
Your answer
![](https://koobas.hobune.stream/wayback/20220612033114im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Web Player and database 1 Answer
Is it possible to dynamically add .fbx files to a unity project from a database during run time 1 Answer
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers