facebook twitter hatena line email

「Unity/Csharp/Request」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
行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="
string param = "value1";
+
      string param = "value1";
url += WWW.EscapeURL (param);
+
      url += WWW.EscapeURL (param);
StartCoroutine(Get (url));
+
      StartCoroutine(Get (url));
  }
+
    }
  public IEnumerator Get (string url) {
+
    public IEnumerator Get (string url) {
        var request = new UnityWebRequest();
+
      var request = new UnityWebRequest();
        request.downloadHandler = new DownloadHandlerBuffer();
+
      request.downloadHandler = new DownloadHandlerBuffer();
        request.url = url;
+
      request.url = url;
        request.SetRequestHeader("Content-Type", "application/json; charset=UTF-8");
+
      request.SetRequestHeader("Content-Type", "application/json; charset=UTF-8");
        request.method = UnityWebRequest.kHttpVerbGET;
+
      request.method = UnityWebRequest.kHttpVerbGET;
        yield return request.Send();
+
      yield return request.Send();
        if (request.isError) {
+
      if (request.isError) {
            Debug.Log(request.error);
+
        Debug.Log(request.error);
        } else {
+
      } else {
            if (request.responseCode == 200) {
+
        if (request.responseCode == 200) {
                Debug.Log(request.downloadHandler.text);
+
        Debug.Log(request.downloadHandler.text);
            }
+
 
         }
 
         }
 +
      }
 
     }
 
     }
}
+
  }

2017年10月1日 (日) 05:19時点における版

 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);
       }
     }
   }
 }