unity api request code example
Example 1: egt request unity
IEnumerator SendRequest(string url, System.Action<string> callback) {
UnityWebRequest request = UnityWebRequest.Get(url);
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
{
Debug.LogError(string.Format("Error: {0}",request.error));
}
else
{
callback(request.downloadhandler.text);
}
}
Example 2: 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
{
Debug.Log(request.downloadHandler.text);
}
}
Example 3: unity html get request
IEnumerator SendRequest()
{
UnityWebRequest request = UnityWebRequest.Get("REQUEST_URL");
yield return request.SendWebRequest();
if(request.isNetworkError || request.isHttpError) {
Debug.Log(request.error);
}
else {
Debug.Log(request.downloadHandler.text);
}
}