/// <summary> /// Post请求 /// </summary> /// <returns></returns> private IEnumerator Post(string url, Dictionary <string, object> postData, IHttpCallBackListener listener) { string temp = url; if (postData.ContainsKey("sessionid")) { string sessionid = (string)postData["sessionid"]; temp += ";jsessionid=" + sessionid; } var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; string json = JsonConvert.SerializeObject(postData, Formatting.Indented, jSetting);//过滤掉空值 Encoding encoding = new UTF8Encoding(); Debug.Log("请求的URl地址是:" + temp); using (WWW www = new WWW(temp, encoding.GetBytes(json))) { yield return(www); if (www.isDone && www.error == null) { listener.OnResponse(www.text); } else { listener.OnFailed(www.error); } } }
/// <summary> /// 发送请求 /// </summary> /// <param name="code">请求类型</param> /// <param name="postData"></param> /// <param name="listener"></param> public void SendHttpRequest(RequestCode code, Dictionary <string, object> postData, IHttpCallBackListener listener) { string url = NetConst.URL_HOST + code.ToString().ToLower(); url += code.ToString().ToLower(); StartCoroutine(Post(url, postData, listener)); }