Unity/Csharp/Request
提供: 初心者エンジニアの簡易メモ
public class ComScript : MonoBehaviour { public void Exec () { string url = "ttp://hogehoge.com/api?name1=" string param = "value1"; url += WWW.EscapeURL (param); StartCoroutine(Get (url)); } public IEnumerator Get (string url) { var request = new UnityWebRequest(); request.downloadHandler = new DownloadHandlerBuffer(); request.url = url; request.SetRequestHeader("Content-Type", "application/json; charset=UTF-8"); request.method = UnityWebRequest.kHttpVerbGET; yield return request.Send(); if (request.isError) { Debug.Log(request.error); } else { if (request.responseCode == 200) { Debug.Log(request.downloadHandler.text); } } } }