We found that when we built a project with Unity 2020.3.22 and noticed that the duration of sending a webRequest and receiving the response is really long!
We also tried to build the project with Unity 2021.2.4 (the latest version) but the duration is still long. So we tried to build it with Unity 2020.3.7 and found that the duration is short!
In this case, we call the same address “https://www.google.com/” and we are in the same predicament when we call the game server.
Here’s the details for your reference.
/// <summary>
/// connect url
/// </summary>
[SerializeField]
string _url = "https://www.google.com/";
/// <summary>
/// Send UnityWebRequest
/// </summary>
public void SendGetRequest()
{
if (_Coroutine == null)
{
_startTime = Time.realtimeSinceStartup;
_Coroutine = StartCoroutine(SendGet());
}
}
IEnumerator SendGet()
{
UnityWebRequest webRequest = UnityWebRequest.Get(_url);
//webRequest.timeout = _timeOut;
webRequest.useHttpContinue = false;
yield return webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.ProtocolError ||
webRequest.result == UnityWebRequest.Result.ConnectionError)
_OnLogEvent.Invoke(string.Format("[Log] UnityWebRequest error
-url = {0}
-result = {1}“, _url, webRequest.error));
else
{
float spendTime = Time.realtimeSinceStartup - _startTime;
_OnLogEvent.Invoke(string.Format(”[Log] UnityWebRequest success
-url = {0}
-spendTime = {1}", _url, spendTime));
}
_Coroutine = null;
yield return null;
}