Beispiel #1
0
        IEnumerator PingHFT()
        {
            string json = JsonUtility.ToJson(new PostCmd("happyFunTimesPingForGame"));

            byte[] bytes   = System.Text.Encoding.UTF8.GetBytes(json);
            var    headers = new Dictionary <string, string>();

            headers["Content-Type"] = "application/json";
            m_www = new WWW(m_url, bytes, headers);

            yield return(m_www);

            string err    = m_www.error;
            string result = m_www.text;

            m_www = null;

            if (String.IsNullOrEmpty(err))
            {
                HFTPing ping = JsonUtility.FromJson <HFTPing>(result);
                if (ping != null && ping.id.Equals("HappyFunTimes"))
                {
                    m_found = true;
                }
            }

            if (!m_found)
            {
                m_log.Tell("error: " + err + ", result:" + result);
            }
        }
Beispiel #2
0
        IEnumerator PingHFT()
        {
            string json = JsonUtility.ToJson(new PostCmd("happyFunTimesPingForGame"));

            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json);
            using (var www = new UnityWebRequest(m_url, UnityWebRequest.kHttpVerbPOST)) {
                www.uploadHandler             = new UploadHandlerRaw(bytes);
                www.uploadHandler.contentType = "application/json";
                www.downloadHandler           = new DownloadHandlerBuffer();
                www.SetRequestHeader("Content-Type", "application/json");
                yield return(www.SendWebRequest());

                string err    = www.error;
                string result = www.downloadHandler.text;

                if (!www.isHttpError && !www.isNetworkError && String.IsNullOrEmpty(err))
                {
                    HFTPing ping = JsonUtility.FromJson <HFTPing>(result);
                    if (ping != null && ping.id.Equals("HappyFunTimes"))
                    {
                        m_found = true;
                    }
                }

                if (!m_found)
                {
                    m_log.Tell("error: " + err + ", result:" + result);
                }
            }
        }