无法从统一的PHP接收数据

时间:2016-11-02 09:57:59

标签: c# php unity3d

我有这个脚本与mySql上的数据库进行交互

    string dataSubmitURL = "http://localhost/HighScore/AddScore.php?";
 string dataGetURL = "http://localhost/HighScore/GetScore.php?";

       // Use this for initialization
        void Start () {
            StartCoroutine(GetScores());
        }

        // Update is called once per frame
        void Update () {

        }

        IEnumerator PostScores(string playerName, int score) {
            string submitURL = dataSubmitURL + "name="+ playerName + "&score=" + score;
            print(submitURL);
            WWW submitData = new WWW(submitURL);
            yield return submitData;
            if (submitData.error != null)
            {
                Debug.LogError("Error occur when Submitting data : " + submitData.error);
                Debug.LogError("Error occur when Submitting data : " + submitData.text);
                Debug.LogError("Error occur when Submitting data : " + submitData.responseHeaders);
                //submitData.text
            }
            else {
                print(" Submitted");
            }

      IEnumerator GetScores() {
            WWW getData = new WWW(dataGetURL);
            yield return getData;
            if (getData.error != null)
            {
                Debug.LogError("There was an error getting the high score: " + getData.error);
            }
            else {
                print(getData.text);
            }
        }
        }

但问题是我得到了

  

获得高分时出错:来自服务器的空回复

虽然这两个网址都是

 string dataSubmitURL = "http://localhost/HighScore/AddScore.php?";
 string dataGetURL = "http://localhost/HighScore/GetScore.php?";

直接把它放在浏览器中正常工作。我还在我的根文件夹中添加了这个crossDomain.xml,以便所有人都可以访问它。我做错了什么。

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

1 个答案:

答案 0 :(得分:0)

我不知道所有代码都是正确的问题是什么,只有通过更改IP地址才能正常工作。

string dataSubmitURL = "http://YouripAddress/HighScore/AddScore.php?";
 string dataGetURL = "http://YouripAddress/HighScore/GetScore.php?";