Unity - WWWForm 不发布变量

问题描述

我在一个项目中工作得很好,但是在第二个项目中,我的 _POST 变量为空。想法?

IEnumerator GetClub()
     {
         Debug.Log("GetClub: - START");
         WWWForm form = new WWWForm();
         form.AddField("state","TX");
         form.AddField("author","MYNAME");
 
         UnityWebRequest res = UnityWebRequest.Post(getglubsURL,form);
 
         yield return res.SendWebRequest();
 
         Debug.Log(res.downloadHandler.text);

PHP文件很简单

<?PHP
 echo "MADE IT  ";
 echo "author: [" . $_POST['author'] . "] ";
 echo "state: [" . $_POST['state'] . "]";
 ?>

和控制台统一是:

MADE IT 作者:[] 状态:[] UnityEngine.Debug:Log(对象)

这在 POSTMAN 中工作正常,所以不确定为什么 Unity Forms 不传递 POST 变量?

解决方法

我也遇到过类似的问题; $_POST 一般为空。

然后我发现 URL 是 "HTTP://website.com/folder",而不是 "HTTP://website.com/folder/"。最后一个 "/" 显然很重要,因为没有它,您会收到 "PAGE MOVED PERMANENTLY" 错误,然后将您重定向到 "HTTP://website.com/folder/index.php" 并丢弃之前的 POST 请求。