Unity中的WWW返回空字符串

Its returning an empty string and I can't seem to figure out why, if you visit the page it outputs fine. (http://lgdev.site.nfoservers.com/getItems.php). I'm trying to get all the data, separate it by certain characters, then use the code in the game t operate it and sort it into the correct places. But like I said its returning an empty string instead of the data that's show on the webpage I gave above.

Game Code:

 public void loadItems()
 {
     WWWForm form = new WWWForm();
     WWW w = new WWW("http://lgdev.site.nfoservers.com/getItems.php", form);
     StartCoroutine(loadItemsFunc(w));
 }

 IEnumerator loadItemsFunc(WWW w)
 {
     yield return w;
     Debug.Log(w.text);
     string[] tmpdata1 = w.text.Split(char.Parse("="));
     foreach(string data in tmpdata1)
     {
         string[] tmpinfo = data.Split(char.Parse("~"));
         GameObject tmpObj = Instantiate(weapon);
         tmpObj.GetComponent<weapon>().name = tmpinfo[0];
         tmpObj.GetComponent<weapon>().vitalisim = int.Parse(tmpinfo[1]);
         tmpObj.GetComponent<weapon>().defence = int.Parse(tmpinfo[2]);
         tmpObj.GetComponent<weapon>().strength = int.Parse(tmpinfo[3]);
         string[] offsetInfo1 = tmpinfo[5].Split(char.Parse(";"));
         foreach (string off in offsetInfo1)
         {
             string[] offset = off.Split(char.Parse(","));
             tmpObj.GetComponent<weapon>().offsetsPos.Add(new Vector3(float.Parse(offset[0]), float.Parse(offset[1]), float.Parse(offset[2])));
             tmpObj.GetComponent<weapon>().offetsRot.Add(new Vector3(float.Parse(offset[3]), float.Parse(offset[4]), float.Parse(offset[5])));
             tmpObj.GetComponent<weapon>().offetsSize.Add(new Vector3(float.Parse(offset[6]), float.Parse(offset[7]), float.Parse(offset[8])));
         }
         string[] typeInfo = tmpinfo[4].Split(char.Parse(","));
         if (tmpinfo[1] == "SwordnShield")
         {
             tmpObj.GetComponent<weapon>().anim = swordAndShieldAnimSet;
         }
         else if (tmpinfo[1] == "TwoHanded")
         {
             tmpObj.GetComponent<weapon>().anim = twoHandedAnimSet;
         }
         foreach (string prefab in tmpinfo[6].Split(char.Parse(",")))
         {
             tmpObj.GetComponent<weapon>().prefabs.Add(prefab);
         }
     }

 }

PHP Code:

<?PHP
     $con = mysql_connect("localhost","user","passs") or ("Cannot connect!"  . mysql_error());
     if (!$con)
     die('Could not connect: ' . mysql_error());

     mysql_select_db("lgdev_projectzed" , $con) or die ("could not load the database" . mysql_error());
     $query = "SELECT * FROM `equipment`";
     $check = mysql_query($query) or die(mysql_error()." ".$query);
     if($check){
     }
     $numrows = mysql_num_rows($check);
     $text = "";
     while ($row = mysql_fetch_array($check, MYSQL_ASSOC)) {
         $text = $text."".$row["name"]."~".$row["vitalism"]."~".$row["defence"]."~".$row["strength"]."~".$row["type"]."~".$row["offsets"]."~". $row["prefabs"] ."=";
     }
     die($text);

 ?>

</div>

1个回答



首先,检查它是否有任何错误:</ p>

  Debug.Log(  w.error);  //在其他debug.log之前或之后放置此文件
</ code> </ pre>

由于您提交的表单为空,因此存在一些错误..
请检查如何设置 您的表单:
https://docs.unity3d.com/ScriptReference/WWWForm.html </ p>

如果您不需要在表单中发布任何内容,可以使用普通的WWW
https://docs.unity3d.com/ScriptReference/WWW.html </ p>
</ div>

展开原文

原文

First, check if it gives any error with:

 Debug.Log(w.error); // place this before or after the other debug.log

Since the form that you submit is empty, there is some error.. So check how to setup your form: https://docs.unity3d.com/ScriptReference/WWWForm.html

If you don't need to post anything in the form, can use the plain WWW https://docs.unity3d.com/ScriptReference/WWW.html

dongzong3053
dongzong3053 只需单击答案上的复选标记图像即可。 i.stack.imgur.com/uqJeW.png
接近 4 年之前 回复
dow72046
dow72046 我怎么做@Programmer
接近 4 年之前 回复
dtn36013
dtn36013 请不要忘记接受答案,因为它适合您。
接近 4 年之前 回复
dongtuanzi1080
dongtuanzi1080 谢谢,一旦我删除了表单部分,它完美地工作:)
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问