I am trying to send JSON to my python flask web server but when I run the code I got "method not allowed" for some reason
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!");
}
}
}
this is the server side:
@app.route('/test', methods = ['POST'])
def testpost():
if request.method == "POST":
data = request.get_json()
print(data)
return jsonify(data)