unity3d - unity unitywebrequest 400 方法不允许错误
问题描述
我正在尝试将 JSON 发送到我的 python 烧瓶 Web 服务器,但是当我运行代码时,由于某种原因,我得到“方法不允许”
IEnumerator Upload()
{
var something = new Data();
//Debug.Log("something: " + something);
var jsonString = JsonUtility.ToJson(something);
//Debug.Log("jsonString: " + jsonString);
using (var www = UnityWebRequest.Post("http://localhost:8000/test", jsonString))
{
www.SetRequestHeader("Content-Type", "application/json");
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Form upload complete!");
}
}
}
这是服务器端:
@app.route('/test', methods = ['POST'])
def testpost():
if request.method == "POST":
data = request.get_json()
print(data)
return jsonify(data)
解决方案
推荐阅读
- specflow - 我可以让 BeforeScenario 和 AfterScenario 挂钩中的场景失败吗?
- swift - 我的函数在里面的数据被处理返回之前返回
- python-3.x - KeyError:使用 API 将数据插入数据库
- reactjs - 更改 jwt 令牌的 Apollo 客户端选项
- maven - Automation of release and dependency management
- logstash - Logstash - 如何用逗号分割数组?
- python - 我无法在 Python (PyCharm) 中输入字母“&”它用空格 {BUG} 替换它
- javascript - 如何将对话框中的用户输入数据保存到隐藏字段中:Jquery 和 HTML
- javascript - 使用 foreach 更新数组的特定列键的每个值
- css - 如何更改字体真棒图标的颜色