public void HttpRequestByMothdType(HTTPMethods methodType, string param, bool isKeepAlive, bool disableCache, Action <int, string, string> callBack) { string url = BaseUrl + SubPath + param; HTTPManager.SendRequest(url, methodType, isKeepAlive, disableCache, (HTTPRequest originalRequest, HTTPResponse response) => { if (response == null) { callBack(-1, "", ""); return; } string responseStr = ""; int result = 0; string msg = ""; if (response.IsSuccess) { responseStr = Encoding.UTF8.GetString(response.Data); } else { result = response.StatusCode; msg = response.Message; } if (callBack != null) { callBack(result, msg, responseStr); } }); }
public void HttpPostUrlRequest(string url, Action <int, string, string> callBack) { Debug.Log("请求:" + url); HTTPManager.SendRequest(url, HTTPMethods.Post, (HTTPRequest originalRequest, HTTPResponse response) => { if (response == null) { callBack(-1, "", ""); return; } string responseStr = ""; int result = 0; string msg = ""; if (response.IsSuccess) { responseStr = Encoding.UTF8.GetString(response.Data); } else { result = response.StatusCode; msg = response.Message; } if (callBack != null) { Debug.Log("错误码:" + result + " 返回:" + msg); Debug.Log("responseStr:" + responseStr); callBack(result, msg, responseStr); } }); }
public void StartDownloadTexture() { if (getTextureStarted || texture != null) { return; } HTTPManager.SendRequest(avatar_url, OnUserAvatarDownloaded); }
private void SendPost(string _subUrl, Dictionary <string, string> _kvs) { HTTPRequest _request = HTTPManager.SendRequest(_subUrl, HTTPMethods.Post, true, true, OnResponse); foreach (System.Collections.Generic.KeyValuePair <string, string> _kvp in _kvs) { _request.AddField(_kvp.Key, _kvp.Value); } _request.Send(); }
public void StartDownload() { Debug.Log("Yes"); var request = new HTTPRequest(new Uri(Spath), OnfragmentDownloaded); request.OnProgress = OnDownloadProgress; request.UseStreaming = true; request.StreamFragmentSize = 1024; HTTPManager.SendRequest(request); }
public static bool SendGetRequest <T>(string url, Action <bool, T> callback = null) where T : NetMessage { if (!CheckMinTime(url)) { Debug.LogError("Send too fast = " + url); return(false); } HTTPRequest req = MakeGetRequest <T>(url, callback); MarkCheck(url); return(HTTPManager.SendRequest(req) != null); }
public void PostRequest(AbstractHttpProtocol proto, Callback <NetworkMsgType, string, AbstractHttpProtocol> onFinish) { this.protoBuffer = proto; this.onFinish = onFinish; Uri uri = new Uri(proto.GetRequestUrl()); HTTPRequest request = new HTTPRequest(uri, HTTPMethods.Post, true, true, OnDownloaded); request.ConnectTimeout = TimeSpan.FromSeconds(connect_time_out); request.Timeout = TimeSpan.FromSeconds(time_out); request.RawData = proto.postBody; request.EnableTimoutForStreaming = true; HTTPManager.SendRequest(request); }
public static bool SendPostRequest <T>(string url, Dictionary <string, object> data, Action <bool, T> callback = null) where T : NetMessage { if (!CheckMinTime(url)) { Debug.LogError("Send too fast = " + url); return(false); } HTTPRequest req = MakePostRequest <T>(url, data, callback); req.Timeout = new TimeSpan(0, 0, 15); #if DEVELOPMENT_BUILD || UNITY_EDITOR Debug.Log("正在请求:" + url + "\n" + JsonMapper.ToJson(data)); #endif MarkCheck(url); return(HTTPManager.SendRequest(req) != null); }
private void SendGet(string _subUrl, Dictionary <string, string> _kvs) { bool _first = true; foreach (System.Collections.Generic.KeyValuePair <string, string> _kvp in _kvs) { if (_first) { _subUrl = Utility.MergeString(_subUrl, "?", _kvp.Key, "=", _kvp.Value); } else { _subUrl = Utility.MergeString(_subUrl, "&", _kvp.Key, "=", _kvp.Value); } _first = false; } HTTPRequest _request = HTTPManager.SendRequest(_subUrl, HTTPMethods.Get, true, true, OnResponse); _request.Send(); }
void StartDownload() { GetComponent <UnityEngine.AudioSource>().clip = clip = null; downloadedBytes = 0; // wav file will be downloaded from this page: http://download.wavetlan.com/SVV/Media/HTTP/http-wav.htm var request = new HTTPRequest(new Uri("https://mzu.mjcdn.cc/8652c521e1f78299bb737d733a825ba3/weeluzD_hxk"), OnfragmentDownloaded); // We will track the download progress request.OnProgress = OnDownloadProgress; // if UseStreaming true then, the given callback will called as soon as possible if at least one // fragment downloaded request.UseStreaming = true; // how big a fragment is. request.StreamFragmentSize = 1024; // start proces the request HTTPManager.SendRequest(request); }
public void HttpPostRequestWithData(string url, string param, Action <int, string, string> callBack) { Debug.Log(BaseUrl); Debug.Log(SubPath); Debug.Log(BaseUrl + SubPath + param); Debug.Log("发送请求:" + url); Debug.Log("发送数据:" + param); HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Post, (HTTPRequest originalRequest, HTTPResponse response) => { string responseStr = ""; int result = 0; string msg = ""; if (originalRequest.State == HTTPRequestStates.Finished) { Debug.Log("网络请求成功:" + response.StatusCode + response.IsSuccess); result = response.StatusCode; msg = response.Message; if (response.IsSuccess) { result = 0; responseStr = Encoding.UTF8.GetString(response.Data); } Debug.Log(responseStr); } else { result = -1; msg = "TimeOut"; } if (callBack != null) { callBack(result, msg, responseStr); } }); request.RawData = Encoding.UTF8.GetBytes(param); Debug.Log(request.Uri); HTTPManager.SendRequest(request); }
public void PerformDownload(Manifest manifest) { manifest.__Start(); manifest.Ping(); string url = manifest.URL; string realURL = System.Uri.EscapeUriString(url); HTTPManager.IsCachingDisabled = true; HTTPMethods methodType = HTTPMethods.Get; if (manifest.POSTFieldKVP.Count > 0) { methodType = HTTPMethods.Post; } HTTPRequest bestHTTPRequest = new HTTPRequest(new System.Uri(realURL), methodType, OnFragmentDownloaded); bestHTTPRequest.UseStreaming = true; bestHTTPRequest.DisableRetry = true; bestHTTPRequest.StreamFragmentSize = 1024; bestHTTPRequest.Tag = manifest; bestHTTPRequest.SetHeader("Accept-Encoding", "deflate"); bestHTTPRequest.OnProgress += OnProgress; // if the request is a POST request, add all relevant fields if (manifest.POSTFieldKVP.Count > 0) { foreach (KeyValuePair <string, string> kvp in manifest.POSTFieldKVP) { bestHTTPRequest.AddField(kvp.Key, kvp.Value); } } manifest.EngineInstance = bestHTTPRequest; HTTPManager.SendRequest(bestHTTPRequest); }
public static void DownloadImage(string imageUrl, int imageSize, OnImageDownloaded onImageDownload, string fallbackImageUrl = "", bool isRetry = false) { ImageDownloader imageDownloaderQueue = CreateInstanceIfNeeded(); if (!string.IsNullOrEmpty(imageUrl)) { if (downloadingImages == null) { downloadingImages = new Dictionary <string, List <OnImageDownloaded> >(); } if (downloadedImages == null) { downloadedImages = new Dictionary <string, Texture2D>(); } if (cachedImageQueue == null) { cachedImageQueue = new List <string>(); } string cacheRef = imageUrl + ":" + imageSize; if (downloadedImages.ContainsKey(cacheRef)) { onImageDownload(downloadedImages[cacheRef]); } else if (downloadingImages.ContainsKey(cacheRef)) { downloadingImages[cacheRef].Add(onImageDownload); } else { try { string url = imageUrl; bool flag = false; if (imageSize != 0 && imageUrl.StartsWith("https://api.vrchat.cloud/api/1/file/")) { string[] array = imageUrl.Remove(0, "https://api.vrchat.cloud/api/1/file/".Length).Split('/'); if (array.Length == 2 || (array.Length == 3 && array[2] == "file")) { string text = array[0]; string text2 = array[1]; url = "https://api.vrchat.cloud/api/1/image/" + text + "/" + text2 + "/" + imageSize.ToString(); flag = true; } } downloadingImages[cacheRef] = new List <OnImageDownloaded>(); HTTPManager.SendRequest(url, HTTPMethods.Get, HTTPManager.KeepAliveDefaultValue, disableCache : false, delegate(HTTPRequest request, HTTPResponse response) { Action loadImage2 = delegate { if (response != null) { Texture2D dataAsTexture2D = response.DataAsTexture2D; EncacheTexture(cacheRef, dataAsTexture2D); onImageDownload(dataAsTexture2D); foreach (OnImageDownloaded item in downloadingImages[cacheRef]) { item(response.DataAsTexture2D); } downloadingImages.Remove(cacheRef); } else { Debug.LogError((object)("No response received: " + ((request.Exception == null) ? "No Exception" : (request.Exception.Message + "\n" + request.Exception.StackTrace)))); DownloadFallbackOrUseErrorImage(fallbackImageUrl, onImageDownload); } }; if (response != null && response.Data == null) { downloadingImages.Remove(cacheRef); HTTPCacheService.DeleteEntity(request.CurrentUri); if (!isRetry) { DownloadImage(imageUrl, imageSize, onImageDownload, fallbackImageUrl, isRetry: true); } } else if (imageDownloaderQueue != null) { imageDownloaderQueue.QueueImageLoad(loadImage2); } }); } catch (Exception ex) { Exception e; Exception ex2 = e = ex; Action loadImage = delegate { Debug.Log((object)("Could not download image " + imageUrl + " - " + e.Message)); DownloadFallbackOrUseErrorImage(fallbackImageUrl, onImageDownload); }; imageDownloaderQueue.QueueImageLoad(loadImage); } } } }
public static bool SendRequest(HTTPRequest req) { return(HTTPManager.SendRequest(req) != null); }