Exemplo n.º 1
0
        public HTTPRequest(Uri uri, HTTPMethods methodType, bool isKeepAlive, bool disableCache, OnRequestFinishedDelegate callback)
        {
            Uri                = uri;
            MethodType         = methodType;
            IsKeepAlive        = isKeepAlive;
            DisableCache       = disableCache;
            Callback           = callback;
            StreamFragmentSize = 4096;
            DisableRetry       = (methodType == HTTPMethods.Post);
            MaxRedirects       = 2147483647;
            RedirectCount      = 0;
            IsCookiesEnabled   = HTTPManager.IsCookiesEnabled;
            int num3 = Downloaded = (DownloadLength = 0);

            DownloadProgressChanged = false;
            State                           = HTTPRequestStates.Initial;
            ConnectTimeout                  = HTTPManager.ConnectTimeout;
            Timeout                         = HTTPManager.RequestTimeout;
            EnableTimoutForStreaming        = false;
            Proxy                           = HTTPManager.Proxy;
            UseUploadStreamLength           = true;
            DisposeUploadStream             = true;
            CustomCertificateVerifyer       = HTTPManager.DefaultCertificateVerifyer;
            CustomClientCredentialsProvider = HTTPManager.DefaultClientCredentialsProvider;
            UseAlternateSSL                 = HTTPManager.UseAlternateSSLDefaultValue;
        }
Exemplo n.º 2
0
    /// <summary>
    /// 发送POST JSOn请求
    /// </summary>
    /// <param name="url"></param>
    /// <param name="message"></param>
    /// <param name="OnRequestFinished"></param>
    public static void POSTJSON(string url, string message, OnRequestFinishedDelegate OnRequestFinished)
    {
        HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Post, OnRequestFinished);

        request.SetHeader("Content-Type", "application/json; charset=UTF-8");
        request.RawData = System.Text.Encoding.UTF8.GetBytes(message);
        request.Send();
    }
Exemplo n.º 3
0
    /// <summary>
    /// 上传图片
    /// </summary>
    /// <param name="url"></param>
    /// <param name="bytes"></param>
    /// <param name="textureName"></param>
    /// <param name="onRequestFinished"></param>
    public static void UpLoadTexture(string url, byte[] bytes, string textureName, OnRequestFinishedDelegate onRequestFinished)
    {
        HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Post, onRequestFinished);

        request.AddField("enctype", "multipart/form-data");
        request.AddBinaryData("file", bytes, textureName, "image/png");
        request.Send();
    }
Exemplo n.º 4
0
        public HTTPRequest(Uri uri, OnRequestFinishedDelegate callback)
            : this(uri, HTTPMethods.Get, HTTPManager.KeepAliveDefaultValue,
#if !BESTHTTP_DISABLE_CACHING
                   HTTPManager.IsCachingDisabled
#else
                   true
#endif
                   , callback)
Exemplo n.º 5
0
        public LocalImageLoader(string localUrl, bool isAndroid, OnRequestFinishedDelegate callback)
        {
//			Debug.Log ("construct LocalImageLoader: ");
            this.Callback      = callback;
            this.IsAlive       = false;
            this.Url           = localUrl;
            this.IsAndroidType = isAndroid;
            imageLoadManager   = ImageLoadManager.GetIntance();
        }
Exemplo n.º 6
0
        public void Delete(Uri url, OnRequestFinishedDelegate callback)
        {
            request = new HTTPRequest(url, HTTPMethods.Delete, (req, resp) =>
            {
                callback(req, resp);
            });

            request.Send();
        }
        public OnRequestFinishedDelegate createRequestCallBack(Action <string> callBack, Action <ResponseErroInfo> errCallBack)
        {
            OnRequestFinishedDelegate mOnRequestFinishedDelegate = delegate(HTTPRequest request, HTTPResponse response)
            {
                Debug.Log("handleResqAndResp");
                handleResqAndResp(request, response, callBack, errCallBack);
            };

            return(mOnRequestFinishedDelegate);
        }
Exemplo n.º 8
0
    /// <summary>
    /// Get方法
    /// </summary>
    /// <param name="SQL"></param>
    /// <param name="onRequestFinished"></param>
    public static void GET(string SQL, OnRequestFinishedDelegate onRequestFinished, string token = null)
    {
        var request = new HTTPRequest(new Uri(SQL), onRequestFinished);

        if (!string.IsNullOrEmpty(token))
        {
            request.SetHeader("Authorization", token);
        }
        request.Send();
    }
Exemplo n.º 9
0
        public void Put(Uri url, object field, OnRequestFinishedDelegate callback)
        {
            request = new HTTPRequest(url, HTTPMethods.Put, (req, resp) =>
            {
                callback(req, resp);
            });

            request.AddHeader("Content-Type", "application/json");
            request.RawData = new System.Text.UTF8Encoding().GetBytes(JsonConvert.SerializeObject(field));
            request.Send();
        }
Exemplo n.º 10
0
    /// <summary>
    /// 修改用户头像
    /// </summary>
    /// <param name="url"></param>
    /// <param name="bytes"></param>
    /// <param name="textureName"></param>
    /// <param name="onRequestFinished"></param>
    /// <param name="token"></param>
    public static void ModifiUserIcon(string url, byte[] bytes, string textureName, OnRequestFinishedDelegate onRequestFinished, string token = null)
    {
        HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Post, onRequestFinished);

        request.AddField("enctype", "multipart/form-data");
        request.AddBinaryData("file", bytes, textureName, "image/png");
        if (!string.IsNullOrEmpty(token))
        {
            request.SetHeader("Authorization", token);
        }
        request.Send();
    }
Exemplo n.º 11
0
    private HTTPRequest RequestCreate(Uri uri, HTTPMethods method, OnRequestFinishedDelegate callback)
    {
        HTTPRequest request = new HTTPRequest(
            uri: uri,
            methodType: method,
            isKeepAlive: true,
            disableCache: true,
            callback: callback
            );

        return(request);
    }
Exemplo n.º 12
0
        private HTTPRequest RequestCreate(Uri uri, HTTPMethods method, OnRequestFinishedDelegate callback)
        {
            HTTPRequest request = new HTTPRequest(
                uri: uri,
                methodType: method,
                isKeepAlive: true,
                disableCache: true,
                callback: callback
                );

            request.AddHeader("Authorization", this.AccessToken);
            request.AddHeader("UserID", this.UserID);
            return(request);
        }
Exemplo n.º 13
0
        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());
        }
Exemplo n.º 14
0
 /// <summary>
 /// OSS  Get
 /// </summary>
 /// <param name="url"></param>
 /// <param name="post"></param>
 /// <param name="OnRequestFinished"></param>
 /// <param name="token"></param>
 public static void OssGet(string url, KeyValuePair <string, string>[] post, OnRequestFinishedDelegate OnRequestFinished, string token = null)
 {
     BestHTTP.HTTPRequest request = new BestHTTP.HTTPRequest(new Uri(url), true, OnRequestFinished);
     request.Timeout        = TimeSpan.FromMinutes(10);
     request.ConnectTimeout = TimeSpan.FromMinutes(5);
     if (post != null)
     {
         foreach (var item in post)
         {
             request.SetHeader(item.Key, item.Value);
         }
     }
     request.Send();
 }
Exemplo n.º 15
0
        private HTTPRequest RequestCreateToJson(Uri uri, HTTPMethods method, OnRequestFinishedDelegate callback, string jstring)
        {
            HTTPRequest request = new HTTPRequest(
                uri: uri,
                methodType: method,
                isKeepAlive: true,
                disableCache: true,
                callback: callback
                );

            request.RawData = ConvertToByteArray(jstring, Encoding.UTF8);
            request.AddHeader("UserID", this.UserID);
            request.AddHeader("Authorization", this.AccessToken);
            request.AddHeader("content-type", "application/json");
            return(request);
        }
Exemplo n.º 16
0
    /// <summary>
    /// Post 方法
    /// </summary>
    /// <param name="url"></param>
    /// <param name="post"></param>
    /// <param name="OnRequestFinished"></param>
    public static void POST(string url, KeyValuePair <string, string>[] post, OnRequestFinishedDelegate OnRequestFinished, string token = null)
    {
        HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Post, OnRequestFinished);

        if (post != null)
        {
            foreach (var item in post)
            {
                request.AddField(item.Key, item.Value);
            }
            if (!string.IsNullOrEmpty(token))
            {
                request.SetHeader("Authorization", token);
            }
        }
        request.Send();
    }
Exemplo n.º 17
0
        /// <summary>
        /// 发送POST 方式的请求
        /// </summary>
        /// <param name="onRequestFinishedDelegate">回调函数</param>
        /// <param name="urlString">请求地址</param>
        /// <param name="paramsDict">请求的普通参数</param>
        /// <param name="parameterModel">请求需要发送的文件数据</param>
        /// <returns>请求对象</returns>
        private HTTPRequest SendPostType(OnRequestFinishedDelegate onRequestFinishedDelegate, string urlString,
                                         Dictionary <string, string> paramsDict, params FileParamModel[] parameterModel)
        {
            HTTPRequest request = new HTTPRequest(new Uri(urlString), HTTPMethods.Post, onRequestFinishedDelegate);



            //普通Post参数

            //文件参数
            if (parameterModel != null && parameterModel.Length > 0)
            {
                foreach (FileParamModel model in parameterModel)
                {
                    request.AddBinaryData(model.FieldName, model.Content, model.FileName, model.MimeType);
                }
                if (paramsDict != null && paramsDict.Count > 0)
                {
                    request.SetHeader("Content-Type", "application/json");
                    foreach (KeyValuePair <string, string> keyValuePair in paramsDict)
                    {
                        request.AddField(keyValuePair.Key, keyValuePair.Value);
                    }
                }
                Debug.Log("有文件参数" + parameterModel.Length);
            }
            else
            {
                request.SetHeader("Content-Type", "application/json");
                RequestModel requestModel = new RequestModel();
                if (paramsDict != null && paramsDict.Count > 0)
                {
                    //foreach (KeyValuePair<string, string> keyValuePair in paramsDict)
                    //{
                    //    requestModel.AddData(keyValuePair.Key, keyValuePair.Value);
                    //}

                    requestModel.data = paramsDict;
                }
                Debug.Log(requestModel.ObjectToJson());
                request.RawData = requestModel.GetBytes();
            }
            //发送
            return(request.Send());
        }
Exemplo n.º 18
0
        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());
        }
Exemplo n.º 19
0
        public static void RequestUsernameExists(string username, string email, OnRequestFinishedDelegate callback)
        {
            HTTPRequest request = new HTTPRequest(new Uri($"https://dev-api.qmedia.com.br/api/player/exists/username/{username}"), (req, res) =>
            {
                if (res.DataAsText == "false")
                {
                    APIService.RequestEmailExists(email, callback);
                }
                else
                {
                    Debug.Log("Usuário existente");
                }
            });

            request.AddHeader("accept", "text/json");
            request.AddHeader("q-imei", SystemInfo.deviceUniqueIdentifier);
            request.Send();
        }
Exemplo n.º 20
0
        public static void RequestEmailExists(string email, OnRequestFinishedDelegate callback)
        {
            HTTPRequest request = new HTTPRequest(new Uri($"https://dev-api.qmedia.com.br/api/player/exists/email/" + email), (req, res) =>
            {
                if (res.DataAsText == "false")
                {
                    Debug.Log("Permitido criar novo usuário.");
                    callback(res);
                }
                else
                {
                    Debug.Log("Email existente");
                }
            });

            request.AddHeader("accept", "text/json");
            request.AddHeader("q-imei", SystemInfo.deviceUniqueIdentifier);
            request.Send();
        }
Exemplo n.º 21
0
        private void CreateHttpRequest(RequestMessageWrapper sendMessageWrapper, OnRequestFinishedDelegate OnFinished_)
        {
            string serverTarget = MessageTargetDefine.GetServerUrl(sendMessageWrapper.MessageBody);

            if (string.IsNullOrEmpty(serverTarget))
            {
                return;
            }

            Uri serverUri = new Uri(EngineCoreEvents.BridgeEvent.GetServerAddress.SafeInvoke() + "/" + serverTarget);

            //<best
            BestHTTP.HTTPRequest request = new HTTPRequest(serverUri, HTTPMethods.Post, OnFinished_);
            request.IsKeepAlive = true;
            request.RawData     = sendMessageWrapper.MessageBody.ToByteArray();;
            request.SetHeader("Content-Type", "application/x-protobuf");
            request.SetHeader("Accept", "application/x-protobuf");
            string accountToken = EngineCoreEvents.SystemEvents.FetchUserIdentification();

            if (!string.IsNullOrEmpty(accountToken))
            {
                request.SetHeader("accessToken", accountToken);
            }

            int send_identifier = ++S_ATOMIC_COUNTER;

            request.SetHeader("sendTime", send_identifier.ToString());

#if UNITY_DEBUG
            DateTime t1    = DateTime.Now;
            TimeSpan t22   = new TimeSpan(t1.Ticks);
            long     time2 = Convert.ToInt64(t22.TotalMilliseconds);

            //Debug.LogWarning($"SENDING TIME :{request.Uri}  {t1.ToString("yyyy/MM/dd HH:mm:ss:fffffff")}");
            sendMessageWrapper.Send_time      = time2;
            sendMessageWrapper.Send_timestamp = t1.ToString("yyyy/MM/dd HH:mm:ss:fffffff");
#else
            sendMessageWrapper.Send_time = CommonUtils.GetCurTimeMillSenconds();
#endif
            HttpSendingCahce.AddToSendingCache(send_identifier.ToString(), sendMessageWrapper);

            request.Send();
        }
Exemplo n.º 22
0
        public static void RequestCompanyCampaign(OnRequestFinishedDelegate callback)
        {
            HTTPRequest request = new HTTPRequest(new Uri($"https://dev-api.qmedia.com.br/api/logged/v1/company-campaign"), (req, res) =>
            {
                if (res.StatusCode == 200)
                {
                    callback(res);
                }
                else
                {
                    Debug.Log("Informar erro.");
                }
            });
            string QToken = Persistance.Persistance.BinaryLoad <string>("q-token");

            request.AddHeader("accept", "text/json");
            request.AddHeader("q-imei", SystemInfo.deviceUniqueIdentifier);
            request.AddHeader("q-token", QToken);
            request.Send();
        }
Exemplo n.º 23
0
        //POST
        public static void RequestLogon(byte[] data, OnRequestFinishedDelegate callback)
        {
            HTTPRequest request = new HTTPRequest(new Uri($"https://dev-api.qmedia.com.br/api/player/logon"), HTTPMethods.Post, (req, res) =>
            {
                if (res.StatusCode == 200)
                {
                    Persistance.Persistance.BinarySave("q-token", res.GetHeaderValues("q-token")[0]);
                    ControllerBase.LoadScene("mainScene");
                }
                else
                {
                    Debug.Log("Usuário ou senha inexistente/incorreta.");
                }

                callback(res);
            });

            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("accept", "text/json");
            request.AddHeader("q-imei", SystemInfo.deviceUniqueIdentifier);
            request.RawData = data;
            request.Send();
        }
Exemplo n.º 24
0
 public static HTTPRequest SendRequest(string url, HTTPMethods methodType, bool isKeepAlive, bool disableCache, OnRequestFinishedDelegate callback)
 {
     return(SendRequest(new HTTPRequest(new Uri(url), methodType, isKeepAlive, disableCache, callback)));
 }
Exemplo n.º 25
0
 public static HTTPRequest SendRequest(string url, HTTPMethods methodType, OnRequestFinishedDelegate callback)
 {
     return(SendRequest(new HTTPRequest(new Uri(url), methodType, callback)));
 }
Exemplo n.º 26
0
 public static HTTPRequest SendRequest(string url, HTTPMethods methodType, bool isKeepAlive, bool disableCache, OnRequestFinishedDelegate callback)
 {
     return SendRequest(new HTTPRequest(new Uri(url), methodType, isKeepAlive, disableCache, callback));
 }
Exemplo n.º 27
0
 public static HTTPRequest SendRequest(string url, HTTPMethods methodType, OnRequestFinishedDelegate callback)
 {
     return SendRequest(new HTTPRequest(new Uri(url), methodType, callback));
 }
Exemplo n.º 28
0
 public LocalImageLoader(string localUrl, OnRequestFinishedDelegate callback)
     : this(localUrl, true, callback)
 {
 }
Exemplo n.º 29
0
 /// <summary>
 /// 发送POST 方式的请求
 /// </summary>
 /// <param name="urlString">请求地址</param>
 /// <param name="onRequestFinishedDelegate">回调函数</param>
 /// <param name="paramsDict">请求的普通参数</param>
 /// <param name="parameterModel">请求需要发送的文件数据</param>
 /// <returns>请求对象</returns>
 //  [Obsolete("该函数不建议使用,建议使用 SendPostType(string, OnSuccessCallBack, OnErrorCallBack) ")]
 private HTTPRequest SendPostType(string urlString, OnRequestFinishedDelegate onRequestFinishedDelegate, Dictionary <string, string> paramsDict, params FileParamModel[] parameterModel)
 {
     return(SendPostType(onRequestFinishedDelegate, urlString, paramsDict, parameterModel));
 }
Exemplo n.º 30
0
    /// <summary>
    /// 下载
    /// </summary>
    /// <param name="filePath"></param>
    /// <param name="onProgress"></param>
    /// <param name="onRequestFinished"></param>
    public static void Download(string filePath, OnDownloadProgressDelegate onProgress, OnRequestFinishedDelegate onRequestFinished)
    {
        var request = new HTTPRequest(new Uri(filePath), onRequestFinished);

        request.OnProgress += onProgress;
        request.Send();
    }
Exemplo n.º 31
0
/// <summary>
/// 上传第三方用户信息
/// </summary>
/// <param name="url"></param>
/// <param name="post"></param>
/// <param name="bytes">用户头像</param>
/// <param name="textureName"></param>
/// <param name="onRequestFinished"></param>
    public static void UploadUserInfo(string url, KeyValuePair <string, string>[] post, byte[] bytes, string textureName, OnRequestFinishedDelegate onRequestFinished)
    {
        HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Post, onRequestFinished);

        if (post != null)
        {
            foreach (var item in post)
            {
                request.AddField(item.Key, item.Value);
            }
        }
        request.AddField("enctype", "multipart/form-data");
        request.AddBinaryData("file", bytes, textureName, "image/png");
        request.Send();
    }
Exemplo n.º 32
0
    public static void ShareComponent(string url, string key, byte[] AudioBytes, string json, OnRequestFinishedDelegate onRequestFinished)
    {
        Debug.Log("上传用户分享文件  " + json);
        HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Post, onRequestFinished);

        byte[] jsonBytes = System.Text.Encoding.UTF8.GetBytes(json);
        request.AddField("enctype", "multipart/form-data");
        request.AddField("key", key);
        request.AddBinaryData("audioFiles", AudioBytes, "vsz.wav", "Audio/wav");
        request.AddBinaryData("jsonFile", jsonBytes, "vsz.json", "json");
        request.Send();
    }