「Unity/Csharp/Request」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「public class ComScript : MonoBehaviour { public void Exec () { string url = "ttp://hogehoge.com/api?name1=" string param = "value1"; url += WWW.EscapeURL (par...」) |
|||
行1: | 行1: | ||
− | public class ComScript : MonoBehaviour { | + | public class ComScript : MonoBehaviour { |
public void Exec () { | public void Exec () { | ||
string url = "ttp://hogehoge.com/api?name1=" | string url = "ttp://hogehoge.com/api?name1=" |
2017年10月1日 (日) 05:17時点における版
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); } } } }