Skip to content

Instantly share code, notes, and snippets.

@emoacht
Created December 31, 2015 22:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save emoacht/89590d4e4571d40f9e1b to your computer and use it in GitHub Desktop.
Save emoacht/89590d4e4571d40f9e1b to your computer and use it in GitHub Desktop.
Sample usage of UnityWebRequest
using System.Collections;
using UnityEngine;
using UnityEngine.Experimental.Networking;
public class UnityWebRequestUsage : MonoBehaviour
{
void Start()
{
StartCoroutine(GetText());
}
IEnumerator GetText()
{
using (UnityWebRequest request = UnityWebRequest.Get("http://unity3d.com/"))
{
yield return request.Send();
if (request.isError) // Error
{
Debug.Log(request.error);
}
else // Success
{
Debug.Log(request.downloadHandler.text);
}
}
}
}
@Lesliehdezg
Copy link

Hi, i need to assign this script to a GAMEOBJECT?
I need receive a text from a server.

@guneyozsan
Copy link

Hi, i need to assign this script to a GAMEOBJECT?
I need receive a text from a server.

Yes, Monobehaviours only function when assigned to a GameObject. So you can run a Coroutine only when on a GameObject.

@BlesauxSufag
Copy link

BlesauxSufag commented Apr 12, 2019

Any sample usage about HTTPS / certificates ? (using auto-signed certificates ?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment