Please excuse my machine translation, as my English is not very good.
I have created an application that communicates with a server using http. The application worked as long as there was an Internet connection.
One day, for a demonstration, I needed to use a LAN that was not connected to the Internet, and when I tried the application, I got a “No Internet Connection” error and the application did not work.
I can access the server URL in my browser, but when I make a request from the application, I get an error.
The server address is a local IP address such as “http://192.168.x.x”.
Does this error occur if the LAN is not connected to the Internet? Or is there a workaround?
Unity version: 2021.3.8f1
Here is the actual code.
public IEnumerator OAuth2Co(string hostUrl, string userId, string password, string cKey, string sKey, Action<string> errorCallback = null)
{
string _requestURL = $"{hostUrl.TrimEnd('/')}/oauth2/token";
WWWForm form = new WWWForm();
form.AddField("grant_type", "password");
form.AddField("username", userId);
form.AddField("password", password);
form.AddField("client_id", cKey);
form.AddField("client_secret", sKey);
using (var req = UnityWebRequest.Post(_requestURL, form))
{
req.SendWebRequest();
while (!req.isDone)
{
yield return null;
}
string msg = $"result:{req.result}, responseCode :{req.responseCode}, error:{req.error}";
Debug.Log(msg);
// output -> result:ConnectionError, responseCode :0, error:No Internet Connection
// Omit the rest of the process
}
}
Well, it’s hard to follow what the actual issue may be. However if you use OAuth to authenticate yourself, don’t you use an external service for that? Or does your own server implement OAuth? Because if your local server does perform the authentication over OAuth via an external provider (google, facebook, … whatever) of course the user can not be authenticated without an internet connection.
If your server does provide his own OAuth interface, it may be that your server actually needs an internet connection.
Other common issues which are quite specific for WebGL builds are: When using external libraries and using CDN links to content providers for those libraries, those of course would not be available without internet. That’s why I prefer to have all javascript libraries that a webbuild needs inside the build or at least on the own server as well. Any external dependencies of course makes you dependent on that external resource and if not available would break your application.
OAuth is implemented on the server side.
Also, the problem occurs in the same way in UnityEditor and iOS builds, so I do not think it is a build-specific issue.