Example #1
0
    /// <summary>
    /// Post网络数据.
    /// </summary>
    IEnumerator SendPost(string _url, WWWForm _wForm, PostCmd cmd)
    {
        WWW postData = new WWW(_url, _wForm);

        yield return(postData);

        if (postData.error != null)
        {
            Debug.Log("Unity:" + "PostError: " + postData.error);
        }
        else
        {
            Debug.Log("Unity:" + cmd + " -> PostData: " + postData.text);
            switch (cmd)
            {
            case PostCmd.BoxLogin:
            {
                JsonData jd = JsonMapper.ToObject(postData.text);
                m_BoxLoginRt = (BoxLoginRt)Convert.ToInt32(jd["code"].ToString());
                if (Convert.ToInt32(jd["code"].ToString()) == (int)BoxLoginRt.Success)
                {
                    m_BoxLoginDt.serverIp = jd["data"]["serverIp"].ToString();
                    m_BoxLoginDt.token    = jd["data"]["token"].ToString();
                    Debug.Log("Unity:" + "serverIp " + m_BoxLoginDt.serverIp + ", token " + m_BoxLoginDt.token);
                    ConnectWebSocketServer();
                }
                else
                {
                    Debug.Log("Unity:" + "Login box failed! code == " + jd["code"]);
                }
                break;
            }
            }
        }
    }
    /// <summary>
    /// Post网络数据.
    /// </summary>
    IEnumerator SendPost(string _url, WWWForm _wForm, PostCmd cmd)
    {
        WWW postData = null;

        if (_wForm == null)
        {
            postData = new WWW(_url);
        }
        else
        {
            postData = new WWW(_url, _wForm);
        }
        yield return(postData);

        if (postData.error != null)
        {
            Debug.Log("Unity:" + "PostError: " + postData.error);
            //网络故障,请检查网络并重启游戏.

            /*if (SSUIRoot.GetInstance().m_GameUIManage != null)
             * {
             *  SSUIRoot.GetInstance().m_GameUIManage.CreatWangLuoGuZhangUI();
             * }*/
        }
        else
        {
            Debug.Log("Unity:" + cmd + " -> PostData: " + postData.text);
            switch (cmd)
            {
            case PostCmd.BoxLogin:
            {
                JsonData jd = JsonMapper.ToObject(postData.text);
                m_BoxLoginRt = (BoxLoginRt)Convert.ToInt32(jd["code"].ToString());
                if (Convert.ToInt32(jd["code"].ToString()) == (int)BoxLoginRt.Success)
                {
                    m_BoxLoginDt.serverIp = jd["data"]["serverIp"].ToString();
                    m_BoxLoginDt.token    = jd["data"]["token"].ToString();
                    Debug.Log("Unity:" + "serverIp " + m_BoxLoginDt.serverIp + ", token " + m_BoxLoginDt.token);
                    ConnectWebSocketServer();
                }
                else
                {
                    Debug.Log("Unity:" + "Login box failed! code == " + jd["code"]);
                }
                break;
            }
            }
        }
    }