Esempio n. 1
0
 private static IEnumerator Generic(string url, string method, JSONObject payload, responseDelegate responseFunction,Dictionary<string,string> headers=null) {
     WWW w;
     if (method == "POST")
     {
         if (headers == null)
             w = new WWW(url, payload);
         else
         {
             WWWForm form = (WWWForm)payload;
             w = new WWW(url, form.data, headers);
         }
     }
     else
     {
         w = new WWW(url);
     }
     yield return w;
     if (!string.IsNullOrEmpty(w.error))
     {
         Debug.Log(w.error);
     }
     else
     {
         responseFunction(new JSONObject(w.text));
     }
 }
Esempio n. 2
0
 public void DelRespDelegate(int protocol, responseDelegate d)
 {
     if (mDelegateMapping.ContainsKey(protocol))
     {
         List <responseDelegate> dels = mDelegateMapping[protocol];
         dels.Remove(d);
     }
 }
Esempio n. 3
0
    /// <summary>
    /// 添加代理,在接受到服务器数据时会下发数据
    /// </summary>
    /// <param name="protocol">Protocol.</param>
    /// <param name="d">D.</param>
    public void AddRespDelegate(int protocol, responseDelegate d)
    {
        List <responseDelegate> dels;

        if (mDelegateMapping.ContainsKey(protocol))
        {
            dels = mDelegateMapping[protocol];
            for (int i = 0; i < dels.Count; i++)
            {
                if (dels[i] == d)
                {
                    return;
                }
            }
        }
        else
        {
            dels = new List <responseDelegate>();
            mDelegateMapping.Add(protocol, dels);
        }
        dels.Add(d);
    }
Esempio n. 4
0
 public static IEnumerator Get(string url, responseDelegate responseFunction)
 {
     return Generic(url, "GET", null, responseFunction);
 }
Esempio n. 5
0
 public static IEnumerator Post(string url, JSONObject payload, responseDelegate responseFunction, Dictionary<string, string> headers = null)
 {
     return Generic(url, "POST", payload, responseFunction, headers);
 }