I'm trying to send a post request to to the website NoRedInk (from this specific request post URL: https://www.noredink.com/login). I've wrote some code, but I'm getting a "HTTP/1.1 422 Unprocessable Entity" error. Upon some research, I've found that this means the URL wasn't able to tell how to parse my payload request data.
I think I need to specify the content type (which shows up as "application/json; charset=utf-8") in my data, but I'm not quite sure the syntax of it. Here's my current code:
private void Start()
{
StartCoroutine(Upload());
}
IEnumerator Upload()
{
WWWForm form = new WWWForm();
form.AddField("login_name", "my_username");
form.AddField("lti_context", "null");
form.AddField("password", "my_password");
//form.AddField("Content-Type", "application/json"); (this is what I tried that didn't work)
using (UnityWebRequest www = UnityWebRequest.Post("https://www.noredink.com/login", form))
{
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log(www.error); // this is where I get the 422 error
}
else
{
print(www.downloadHandler.text)
}
}
}