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)); } }
public void DelRespDelegate(int protocol, responseDelegate d) { if (mDelegateMapping.ContainsKey(protocol)) { List <responseDelegate> dels = mDelegateMapping[protocol]; dels.Remove(d); } }
/// <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); }
public static IEnumerator Get(string url, responseDelegate responseFunction) { return Generic(url, "GET", null, responseFunction); }
public static IEnumerator Post(string url, JSONObject payload, responseDelegate responseFunction, Dictionary<string, string> headers = null) { return Generic(url, "POST", payload, responseFunction, headers); }