Unity: POST request using WWW class using JSON

后端 未结 4 1511
情话喂你
情话喂你 2021-01-07 01:18

I am trying to make a POST request to restful web APIs in Unity.

The header would be Content-Type: application/json

An example of the raw data i

4条回答
  •  轮回少年
    2021-01-07 01:37

    If you want to add raw json data it is better to just pass it without WWWForm

    public WWW POST()
    {
        WWW www;
        Hashtable postHeader = new Hashtable();
        postHeader.Add("Content-Type", "application/json");
    
        // convert json string to byte
        var formData = System.Text.Encoding.UTF8.GetBytes(jsonStr);
    
        www = new WWW(POSTAddUserURL, formData, postHeader);
        StartCoroutine(WaitForRequest(www));
        return www;
    }
    

提交回复
热议问题