我正在尝试将 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)