unity pull html source unity web request code example

Example 1: how to do a web request unity

IEnumerator SendRequest(string url)
    {
        UnityWebRequest request = UnityWebRequest.Get(url);
        yield return request.SendWebRequest();

        if (request.isNetworkError || request.isHttpError)
        {
            Debug.LogError(string.Format("Error: {0}",request.error));
        }

        else
        {
            // Response can be accessed through: request.downloadHandler.text
            Debug.Log(request.downloadHandler.text);
        }
    }

Example 2: 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);
	}
}