Esempio n. 1
0
    static int HttpUpMorePhoto(ILuaState lua)
    {
        string tag     = lua.ChkString(1);
        string url     = lua.ChkString(2);
        float  timeout = (float)lua.OptNumber(10, 10);

        WWWForm wf     = null;
        var     joPost = lua.ToJsonObj(3) as TinyJSON.ProxyObject;

        if (joPost != null)
        {
            wf = KeyValue2Form(joPost);
        }
        for (int i = 0; i < 6; i++)
        {
            var obj = lua.ToAnyObject(4 + i);
            if (obj.Equals(null))
            {
                continue;
            }
            Texture2D texture = obj as Texture2D;
            if (texture.Equals(null))
            {
                continue;
            }
            wf.AddBinaryData("photo", texture.EncodeToPNG());
        }

        // "key:value\nkey:value"
        Dictionary <string, string> headers = new Dictionary <string, string>();

        var httpHandler = NetworkMgr.Instance.GetHttpHandler("HTTP");

        if (httpHandler)
        {
            httpHandler.StartPost(tag, url, "", wf, headers, timeout);
            NetworkMgr.Log("WWW Post: {0}\n{1}", url, KeyValue2Param(joPost));
        }
        return(0);
    }
Esempio n. 2
0
    static int HttpUpPhoto(ILuaState lua)
    {
        string tag       = lua.ChkString(1);
        string url       = lua.ChkString(2);
        string strHeader = lua.ChkString(6);
        float  timeout   = (float)lua.OptNumber(7, 10);

        string param = null;
        var    luaT  = lua.Type(3);

        if (luaT == LuaTypes.LUA_TSTRING)
        {
            param = lua.ToString(3);
        }
        else
        {
            var joParam = lua.ToJsonObj(3) as TinyJSON.ProxyObject;
            if (joParam != null)
            {
                param = KeyValue2Param(joParam);
            }
        }
        WWWForm wf     = null;
        var     joPost = lua.ToJsonObj(4) as TinyJSON.ProxyObject;

        if (joPost != null)
        {
            wf = KeyValue2Form(joPost);
        }
        var       obj     = lua.ToAnyObject(5);
        Texture2D texture = obj as Texture2D;

        wf.AddBinaryData("photo", texture.EncodeToPNG());

        //var joPhoto = lua.ToJsonObj(5) as TinyJSON.ProxyObject;
        //if (joPhoto != null) {
        //    wf = KeyPhoto2Form(joPhoto, wf);
        //}

        // "key:value\nkey:value"
        Dictionary <string, string> headers = new Dictionary <string, string>();

        if (!string.IsNullOrEmpty(strHeader))
        {
            string[] segs = strHeader.Split('\n');
            foreach (string seg in segs)
            {
                string[] kv = seg.Split(':');
                if (kv.Length == 2)
                {
                    headers.Add(kv[0].Trim(), kv[1].Trim());
                }
            }
        }

        var httpHandler = NetworkMgr.Instance.GetHttpHandler("HTTP");

        if (httpHandler)
        {
            httpHandler.StartPost(tag, url, param, wf, headers, timeout);
            NetworkMgr.Log("WWW Post: {0}\n{1}", url + "?" + param, KeyValue2Param(joPost));
        }
        return(0);
    }