Unity: POST request using WWW class using JSON
<p>I am trying to make a POST request to restful web APIs in Unity.</p>

<p>The header would be <code>Content-Type: application/json</code></p>

<p>An example of the raw data input is, where data is the key and json string is the value:</p>

<pre><code>{  
   "data":{  
      "username":"name",
      "email":"email@gmail.com",
      "age_range":21,
      "gender":"male",
      "location":"california"
   }
}
</code></pre>

<p>Here's my script:</p>

<pre><code>private static readonly string POSTAddUserURL = "http://db.url.com/api/addUser";
public WWW POST()
{
    WWW www;
    Hashtable postHeader = new Hashtable();
    postHeader.Add("Content-Type", "application/json");
    WWWForm form = new WWWForm();
    form.AddField("data", jsonStr);
    www = new WWW(POSTAddUserURL, form);
    StartCoroutine(WaitForRequest(www));
    return www;
}

IEnumerator WaitForRequest(WWW data)
{
    yield return data; // Wait until the download is done
    if (data.error != null)
    {
        MainUI.ShowDebug("There was an error sending request: " + data.error);
    }
    else
    {
        MainUI.ShowDebug("WWW Request: " + data.text);
    }
}
</code></pre>

<p>How do I send the request using <code>WWW</code> class with both form and header? Or, just in general, how do I send this kind of post request?</p>