unityWebRequest get returned data code example

Example 1: unity html get request

// Call Method Through: StartCourotine(SendRequest());

IEnumerator SendRequest() 
{
	UnityWebRequest request = UnityWebRequest.Get("REQUEST_URL");
	yield return request.SendWebRequest();
 
	if(request.isNetworkError || request.isHttpError) {
      	// Error Occurred
		Debug.Log(request.error);
	}
	
  	else {
      	// Response can be accessed through: request.downloadHandler.text
		Debug.Log(request.downloadHandler.text);
	}
}

Example 2: unityWebRequest get returned data

string URL = "google.com";

UnityWebRequest www = UnityWebRequest.Get(URL);
www.SendWebRequest();

Debug.Log(www.downloadHandler.text);

Tags:

Misc Example