string url = "https://example.com/api/data"; WWW www = new WWW(url); yield return www; if (www.error != null) { Debug.Log("Error: " + www.error); } else { Debug.Log("Response: " + www.text); }
string url = "https://example.com/api/data"; string jsonBody = "{\"name\": \"John\", \"age\": 25}"; DictionaryThis example sends a POST request to the URL specified with a JSON payload. It also sets the header to specify that the content type is JSON. The response is handled the same as in the previous example.headers = new Dictionary (); headers.Add("Content-Type", "application/json"); byte[] requestBody = System.Text.Encoding.UTF8.GetBytes(jsonBody); WWW www = new WWW(url, requestBody, headers); yield return www; if (www.error != null) { Debug.Log("Error: " + www.error); } else { Debug.Log("Response: " + www.text); }