I’ve searched the problem, but didn’t found any solution, even tough I’ve seen similar questions beign asked.
I’m receiving HTTP/1.1 500 Internal Server Error
In line 26, there is a Debug.log(txt), which is the string created from the JsonUtility.ToJson(). I copied this txt and pasted in Postman and it worked just fine. So I don’t know what I could be doing wrong.
Thanks in advance.
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class TEST : MonoBehaviour
{
[Serializable]
public class Player
{
public string name;
public int score;
public Player(string name, int score)
{
this.name = name;
this.score = score;
}
}
void Start()
{
Player p = new Player("MMM", 200);
string txt = JsonUtility.ToJson(p);
Debug.Log(txt);
StartCoroutine(Post("valid url, same as used in postman", txt));
}
IEnumerator Post(string uri, string postData)
{
using (UnityWebRequest www = UnityWebRequest.Post(uri, postData))
{
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Form upload complete!");
}
}
}
}