public static HTTPRequest HttpsImagePost(string uri, byte[] data, OnRequestFinishedDelegate onRequestFinishedDelegate) { HTTPRequest httpRequest = new HTTPRequest(new Uri(uri), HTTPMethods.Post, onRequestFinishedDelegate); httpRequest.UseAlternateSSL = true; httpRequest.StreamFragmentSize = 100 * 1024; httpRequest.AddHeader("did", SystemInfoUtil.getDeviceUniqueIdentifier()); httpRequest.AddHeader("md5at", GameCache.Instance.strToken); httpRequest.AddField("user_id", $"{GameCache.Instance.nUserId}"); httpRequest.AddBinaryData("file", data, "picture.png", "image/png"); // Log.Debug(httpRequest.DumpHeaders()); return(httpRequest.Send()); }
public static HTTPRequest HttpsPost(string uri, string json, OnRequestFinishedDelegate onRequestFinishedDelegate) { HTTPRequest httpRequest = new HTTPRequest(new Uri(uri), HTTPMethods.Post, onRequestFinishedDelegate); httpRequest.UseAlternateSSL = true; httpRequest.AddHeader("Content-Type", "application/json"); httpRequest.AddHeader("did", SystemInfoUtil.getDeviceUniqueIdentifier()); httpRequest.AddHeader("md5at", GameCache.Instance.strToken); byte[] bytes = json.ToUtf8(); string sh2sg = encrypt(bytes); httpRequest.AddHeader("sh2sg", sh2sg); httpRequest.RawData = bytes; // Log.Debug(httpRequest.DumpHeaders()); return(httpRequest.Send()); }
public async void SendPicUpload(string _apiUrl, byte[] data, Action <string> _call) { UIComponent.Instance.Prompt(); string url = $"{GlobalData.Instance.UploadURL}{_apiUrl}"; Log.Debug($"SendPicUpload send url = {url} | data = {data} | data.Length = {data.Length}"); NetHttpComponent netHttp = ETModel.Game.Scene.GetComponent <NetHttpComponent>(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("did", SystemInfoUtil.getDeviceUniqueIdentifier()); dic.Add("md5at", GameCache.Instance.strToken); Dictionary <string, string> form = new Dictionary <string, string>(); form.Add("user_id", $"{GameCache.Instance.nUserId}"); string res = await netHttp.PostUpload(url, dic, form, "file", data, "picture.png", "image/png"); UIComponent.Instance.ClosePrompt(); if (null != _call) { _call(res); } return; requests.Add(GameUtil.HttpsImagePost(url, data, (request, response) => { RemoveRequest(request); switch (request.State) { case HTTPRequestStates.Finished: if (response.IsSuccess) { _call(response.DataAsText); } break; case HTTPRequestStates.Error: string exception = request.Exception != null ? (request.Exception.Message + "\n" + request.Exception.StackTrace) : "No Exception"; Log.Debug($"Request Finished with Error! {exception}"); UIComponent.Instance.Toast("网络错误"); break; case HTTPRequestStates.Aborted: Log.Debug($"Request Aborted!"); UIComponent.Instance.Toast("网络错误"); break; case HTTPRequestStates.ConnectionTimedOut: Log.Debug($"Connection Timed Out!"); UIComponent.Instance.Toast("网络超时"); break; case HTTPRequestStates.TimedOut: Log.Debug($"Processing the request Timed Out!"); UIComponent.Instance.Toast("网络超时"); break; } }), (int)HTTPRequestStates.Initial); }