using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Net; using System.Text; using UnityEngine; namespace StartAot { public class HttpRequest : SingletonMonobehaviour { public const string defaultHttpContentType = "application/x-www-form-urlencoded"; public const string jsonHttpContentType = "application/json ; charset=utf-8"; public void RequestHttpPost(string _url, IDictionary _parameters, string _contentType, int _retry = 3, Action _result = null) { var content = HashtablaToString(_parameters); HttpBehaviour.Create(_url, "POST", content, _contentType, _retry, _result); } public void RequestHttpPost(string _url, string _content, string _contentType, int _retry = 3, Action _result = null) { HttpBehaviour.Create(_url, "POST", _content, _contentType, _retry, _result); } public void RequestHttpGet(string _url, string _contentType, int _retry = 3, Action _result = null) { HttpBehaviour.Create(_url, "GET", "", _contentType, _retry, _result); } static StringBuilder buffer = new StringBuilder(); public static string HashtablaToString(IDictionary parameters) { buffer.Remove(0, buffer.Length); int i = 0; foreach (KeyValuePair item in parameters) { if (i > 0) { buffer.AppendFormat("&{0}={1}", item.Key, item.Value); } else { buffer.AppendFormat("{0}={1}", item.Key, item.Value); } i++; } string result = buffer.ToString(); return result; } } }