IEnumerator SendPost(string url, XLua.LuaTable table, System.Action <string> callback) { WWWForm form = new WWWForm(); var keys = table.GetKeys <string>(); foreach (string key in keys) { //print(string.Format("key = {0}, value = {1}", key, table.Get<string>(key))); form.AddField(key, table.Get <string>(key)); } WWW getData = new WWW(url, form); yield return(getData); if (!string.IsNullOrEmpty(getData.error)) { Debug.LogFormat("getData.error = {0}", getData.error); Debug.LogFormat("getData.text = {0}", getData.text); } if (!string.IsNullOrEmpty(getData.text)) { callback(getData.text); } else { callback(getData.error); } }
public string MakeJson(XLua.LuaTable table) { var keys = table.GetKeys <string>(); Dictionary <string, string> tempdict = new Dictionary <string, string>(); foreach (string key in keys) { //Debug.LogFormat("key = {0}, value = {1}", key, table.Get<string>(key)); tempdict.Add(key, table.Get <string>(key)); } return(MiniJSON.Json.Serialize(tempdict)); }
/// <summary> /// 开放给Lua端调用的Post接口 /// </summary> /// <param name="url">URL</param> /// <param name="values">值表</param> /// <param name="files">文件表,会以二进制的形式向服务端请求(通过WWWForm.AddBinaryData的形式)</param> /// <param name="cb">回调</param> public void POST(string url, XLua.LuaTable values, XLua.LuaTable files, POSTCB cb) { Dictionary <string, string> data = new Dictionary <string, string>(); IDictionaryEnumerator de = null; if (values != null) { //de = values.GetEnumerator(); //while (de.MoveNext()) //{ // data.Add(de.Key as string, de.Value as string); //} foreach (string key in values.GetKeys <string>()) { data.Add(key, values.Get <string>(key)); } } Dictionary <string, KeyValuePair <string, byte[]> > stream = new Dictionary <string, KeyValuePair <string, byte[]> >(); if (files != null) { //de = files.GetEnumerator(); //while (de.MoveNext()) //{ // string field = de.Key as string; // string path = de.Value as string; // if (string.IsNullOrEmpty(path) || !File.Exists(path)) // { // GameDebug.LogWarning(string.Format("Unexpect path:{0}", path)); // continue; // } // byte[] bytes = File.ReadAllBytes(path); // stream.Add(field, new KeyValuePair<string, byte[]>(Path.GetFileName(path), bytes)); //} foreach (string field in files.GetKeys <string>()) { string path = values.Get <string>(field); if (string.IsNullOrEmpty(path) || !File.Exists(path)) { GameDebug.LogWarning(string.Format("Unexpect path:{0}", path)); continue; } byte[] bytes = File.ReadAllBytes(path); stream.Add(field, new KeyValuePair <string, byte[]>(Path.GetFileName(path), bytes)); } } POST(url, data, stream, cb, null); }
static int _m_GetKeys(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLua.LuaTable __cl_gen_to_be_invoked = (XLua.LuaTable)translator.FastGetCSObj(L, 1); try { { System.Collections.IEnumerable __cl_gen_ret = __cl_gen_to_be_invoked.GetKeys( ); translator.Push(L, __cl_gen_ret); return(1); } } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } }