44 lines
1,003 B
C#
44 lines
1,003 B
C#
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using System.Collections;
|
|
using UnityEngine.UI;
|
|
|
|
public class GetData : MonoBehaviour
|
|
{
|
|
//string displayText = "";
|
|
Text objectText;
|
|
|
|
void Start()
|
|
{
|
|
objectText = GetComponentInParent<Text> ();
|
|
}
|
|
|
|
public void DisplayStuff()
|
|
{
|
|
StartCoroutine (MakeRequest ());
|
|
//Debug.Log (displayText);
|
|
//objectText.text = displayText;
|
|
}
|
|
|
|
IEnumerator MakeRequest()
|
|
{
|
|
using (UnityWebRequest www = UnityWebRequest.Get("https://corder.tech/mocha/users/1"))
|
|
{
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.Log(www.error);
|
|
}
|
|
else
|
|
{
|
|
// Show results as text
|
|
//Debug.Log(www.downloadHandler.text);
|
|
objectText.text = www.downloadHandler.text;
|
|
|
|
// Or retrieve results as binary data
|
|
byte[] results = www.downloadHandler.data;
|
|
}
|
|
}
|
|
}
|
|
}
|