Can't fetch site as string. Unitywebrequest

How it will look in new UnityWebrequest?

string result = String.Empty;
while (connectionRetries < maxRetries)
                    {
                        WWW www = new WWW(mySite.url);
    
                        while (!www.isDone)
                            yield return null;
    
                        if (!string.IsNullOrEmpty(www.error))
                        {
                            connectionRetries++;
                            Debug.LogWarning("Error Loading My Site " + mySite.url + ". Retrying connection " + connectionRetries);
                            errorMessage = www.error;
                        }
                        else
                        {
                           result = www.text;
                            break;
                        }
                    }

It does work like this, but when i try changing to UnityWebRequest it doesnt. Can’t fetch site as string.

string result = String.Empty;
while (connectionRetries < maxRetries)
                    {
                        UnityWebRequest www = UnityWebRequest.Get("mySite.url");
    
                        while (!www.isDone)
                            yield return null;
    
                        if (!string.IsNullOrEmpty(www.error))
                        {
                            connectionRetries++;
                            Debug.LogWarning("Error Loading My Site " + mySite.url + ". Retrying connection " + connectionRetries);
                            errorMessage = www.error;
                        }
                        else
                        {
                           result = www.downloadHandler.text;
                            break;
                        }
                    }

Also tried:
result = www.downloadHandler.text.ToString();

Help?

You haven’t actually send your webrequest. Unity’s old WWW class immediately sends out the request when you create it. The UnityWebRequest allows more advanced requests where you can change the request headers and upload data after you created the web request. You have to call UnityWebRequest.SendWebRequest to actually send the request to the target server.

Note that busy waiting on isDone is not recommended and might break on certain platforms (like WebGL) since WebGL doesn’t support multi threading (yet). It’s always recommended to use a coroutine and yield on the result that the SendWebRequest method returns. Just have a look at the example code in the documenation