www.text在Unity3D中返回奇怪的值(C#)

Emm*_*mma 6 c# http unity-game-engine get-request

我正在使用Unity 3D的WWW来发出http请求:http://docs.unity3d.com/ScriptReference/WWW.html

似乎无论我试图访问什么样的数据,它只会返回: 每次.我已经尝试过json文件,我尝试过只生成一个字符串的php.我似乎无法访问服务器上的值.

C#:

public string url = "http://www.onelittledesigner.com/data.php";

IEnumerator Start() {
    WWW www = new WWW(url);
    yield return www;

    if (!string.IsNullOrEmpty(www.error)) {
        Debug.Log(www.error);
    } else {
        Debug.Log(www.text);
    }

}
Run Code Online (Sandbox Code Playgroud)

PHP:

<?php
  echo "textiness";
?>
Run Code Online (Sandbox Code Playgroud)

注意: 我已成功使用www.texture将图像从服务器中拉出.但是,www.text似乎不起作用.

Krz*_*rko 2

复制评论中的答案,并进行一些附加测试。我的结果在评论里。请注意,使用默认、ASCII 或 UTF8 确实可以在我的机器上运行 - 它也应该在您的机器上运行。

\n\n
    // returned from www.bytes, copied here for readability\n    byte[] bytes=new byte[]{116, 101, 120, 116, 105, 110, 101, 115, 115};\n\n    string customDecoded=""; \n    foreach(var b in bytes)\n        customDecoded+=(char)b; \n\n    Debug.Log(customDecoded); // textiness\n    Debug.Log(System.Text.Encoding.Default); // System.Text.ASCIIEncoding\n    Debug.Log(System.Text.Encoding.Default.GetString(bytes));  // textiness\n    Debug.Log(System.Text.Encoding.ASCII.GetString(bytes));  // textiness\n    Debug.Log(System.Text.Encoding.Unicode.GetString(bytes)); // \xe6\x95\xb4\xe7\x91\xb8\xe6\xb9\xa9\xe7\x8d\xa5\n    Debug.Log(System.Text.Encoding.UTF7.GetString(bytes)); // textiness\n    Debug.Log(System.Text.Encoding.UTF8.GetString(bytes)); // textiness\n    Debug.Log(System.Text.Encoding.UTF32.GetString(bytes)); // \xe6\x95\xb4\xe6\xb9\xa9\n    Debug.Log(System.Text.Encoding.BigEndianUnicode.GetString(bytes)); // \xe7\x91\xa5\xe7\xa1\xb4\xe6\xa5\xae\xe6\x95\xb3\n
Run Code Online (Sandbox Code Playgroud)\n\n

请检查是否System.Text.Encoding.Default是 ASCIIEncoding,也许有什么改变了默认值?

\n