static int _m_SendHttpMsg_xlua_st_(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);



                {
                    string url    = LuaAPI.lua_tostring(L, 1);
                    string method = LuaAPI.lua_tostring(L, 2);
                    System.Collections.Generic.Dictionary <string, object> param = (System.Collections.Generic.Dictionary <string, object>)translator.GetObject(L, 3, typeof(System.Collections.Generic.Dictionary <string, object>));
                    HttpMsgCallback callback = translator.GetDelegate <HttpMsgCallback>(L, 4);

                    BoyApp.SendHttpMsg(url, method, param, callback);



                    return(0);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }
        }
    public static IEnumerator SendHttpMsg(string url, string method, Dictionary <string, object> param, HttpMsgCallback callback)
    {
        if (string.Compare(method, "get", true) == 0)
        {
            UnityWebRequest getTW = null;
            if (param == null || param.Count == 0)
            {
                getTW = UnityWebRequest.Get(url);
            }
            else
            {
                StringBuilder strParams = new StringBuilder();
                bool          first     = true;
                foreach (KeyValuePair <string, object> val in param)
                {
                    if (first == false)
                    {
                        strParams.Append("&");
                    }
                    strParams.AppendFormat("{0}={1}", val.Key, val.Value.ToString());
                    first = false;
                }
                getTW = UnityWebRequest.Get(string.Format("{0}?{1}", url, strParams.ToString()));
            }
            getTW.method  = UnityWebRequest.kHttpVerbGET;
            getTW.timeout = TimeOut;
            yield return(getTW.SendWebRequest());

            if (getTW.isDone)
            {
                if (getTW.error != null)
                {
                    callback(getTW.error, null);
                }
                else
                {
                    callback(null, getTW.downloadHandler.text);
                }
            }
            else
            {
                callback("sendHttpMsg get not done", null);
            }
        }
        else if (string.Compare(method, "post", true) == 0)
        {
            WWWForm postForm = new WWWForm();
            if (param != null)
            {
                foreach (KeyValuePair <string, object> val in param)
                {
                    postForm.AddField(val.Key, val.Value.ToString());
                }
            }
            UnityWebRequest postTW = UnityWebRequest.Post(url, postForm);
            yield return(postTW.SendWebRequest());

            if (postTW.isDone)
            {
                if (postTW.error != null)
                {
                    callback(postTW.error, null);
                }
                else
                {
                    callback(null, postTW.downloadHandler.text);
                }
            }
            else
            {
                callback("sendHttpMsg get not done", null);
            }
        }
        else
        {
            throw new Exception("HttpUtils->SendHttpMsg->not support " + method);
        }
    }
Exemplo n.º 3
0
    public static void SendHttpMsgWithSign(string url, string method, Dictionary <string, object> param, HttpMsgCallback callback, string appkey)
    {
        if (param == null)
        {
            param = new Dictionary <string, object>();
        }
        param["ts"] = DateUtils.GetTimeStamp();

        string[] keys = new string[param.Keys.Count];
        param.Keys.CopyTo(keys, 0);

        Array.Sort(keys);

        StringBuilder noSignStr = new StringBuilder();

        foreach (var key in keys)
        {
            noSignStr.AppendFormat("{0}={1}&", key, param[key]);
        }
        noSignStr.AppendFormat("key={0}", appkey);

        param["sign"] = noSignStr.ToString().ToMD5();

        SendHttpMsg(url, method, param, callback);
    }
Exemplo n.º 4
0
 public static void SendHttpMsg(string url, string method, Dictionary <string, object> param, HttpMsgCallback callback)
 {
     Instance.StartCoroutine(HttpUtils.SendHttpMsg(url, method, param, callback));
 }