示例#1
0
    // GETを実際に処理してるコルーチン
    private IEnumerator HttpGetCoroutine(
        OnCompletionGet successFunction,
        OnErrorGet errorFunction,
        string url,
        string siteName)
    {
        Debug.Log("start coroutine in " + siteName);
        UnityWebRequest request = UnityWebRequest.Get(url);

        // リクエスト送信
        yield return(request.Send());

        // 通信エラーチェック
        if (request.isError)
        {
            //エラー処理
            errorFunction(request, siteName);
        }
        else
        {
            if (request.responseCode == 200)
            {
                // UTF8文字列として取得する
                string text = request.downloadHandler.text;
                //接続成功
                successFunction(request, siteName);
            }
        }
    }
示例#2
0
 // GET(tagなし)の開始処理
 public void StartGet(OnCompletionGet completion,
                      OnErrorGet errorHandler,
                      string url,
                      string siteName)
 {
     Debug.Log("start coroutine " + siteName);
     StartCoroutine(HttpGetCoroutine(
                        completion,
                        errorHandler,
                        url,
                        siteName
                        ));
 }