示例#1
0
        //public static Response<T> HttpGet<T>(string address, string contentType = contentTypeJson) where T : class
        //{
        //    return HttpGet<T>(address, Encoding.UTF8, contentType, null);
        //}

        //public async static Task<Response<TResponse>> EncryptedHttpGetAsync<TResponse>(string url, string decPriKey) where TResponse : class
        //{
        //    try
        //    {
        //        var response = await NetHelper.HttpGetAsync<EncryptedMessage>(url);

        //        if (response.HasNotNullResult())
        //        {
        //            return ResponseFactory.Create<TResponse>(response.Result.Decrypt<TResponse>(decPriKey));
        //        }
        //        else
        //        {
        //            return ResponseFactory.CreateError<TResponse>(response.ErrorMessage);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        return ResponseFactory.CreateError<TResponse>(ex.Message);
        //    }
        //}

        //Http Post
        //public static async Task<Response<T>> HttpPostAsync<T>(string address, object data, WebProxy proxy, string contentType = contentTypeJson)
        //{
        //    return await HttpPostAsync<T>(address, data, Encoding.UTF8, proxy, contentType);
        //}

        //public static Response<T> HttpPost<T>(string address, object data, string contentType = contentTypeJson) where T : class
        //{
        //    return HttpPost<T>(address, data, Encoding.UTF8, null, contentType, null);
        //}

        #endregion


        public static async Task <Response <T> > HttpPostAsync <T>(HttpParameters parameters)
        //string address,
        //object data,
        //Encoding encoding = null,
        //WebProxy proxy = null,
        //string bearer = null,
        //string contentType = contentTypeJson,
        //Dictionary<string, string> headers = null)
        {
            return(await UploadStringTaskAsync <T>(parameters, WebRequestMethods.Http.Post));

            //try
            //{
            //    var client = CreateWebClient(contentType, encoding, proxy, bearer, headers);

            //    var stringData = Newtonsoft.Json.JsonConvert.SerializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()
            //    {
            //        NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            //    });

            //    var stringResult = await client.UploadStringTaskAsync(address, stringData);

            //    var result = ResponseFactory.Create(Newtonsoft.Json.JsonConvert.DeserializeObject<T>(stringResult));

            //    return result;
            //}
            //catch (Exception ex)
            //{
            //    return ResponseFactory.CreateError<T>(ex.Message);
            //}
        }
示例#2
0
        public static Response <T> HttpPost <T>(HttpParameters parameters) where T : class
        {
            try
            {
                var result = HttpPostString(parameters);

                return(ResponseFactory.Create <T>(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(result.Result)));
            }
            catch (Exception ex)
            {
                return(ResponseFactory.CreateError <T>(ex.GetFullMessage()));
            }
        }
示例#3
0
        private static Response <string> HttpUploadString(HttpParameters parameters, string httpMethod)
        {
            try
            {
                var client = CreateWebClient(parameters.ContentType, parameters.Encoding, parameters.Proxy, parameters.Bearer, parameters.Headers);

                var stringData = Newtonsoft.Json.JsonConvert.SerializeObject(parameters.Data, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                });

                var stringResult = client.UploadString(parameters.Address, httpMethod, stringData);

                return(ResponseFactory.Create(stringResult));
            }
            catch (Exception ex)
            {
                return(ResponseFactory.CreateError <string>(ex.Message));
            }
        }
示例#4
0
        public static Response <string> HttpPostString(HttpParameters parameters)
        {
            return(HttpUploadString(parameters, WebRequestMethods.Http.Post));
            //try
            //{
            //    var client = CreateWebClient(contentType, encoding, proxy, bearer, headers);

            //    var stringData = Newtonsoft.Json.JsonConvert.SerializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()
            //    {
            //        NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            //    });

            //    var stringResult = client.UploadString(address, stringData);

            //    return ResponseFactory.Create(stringResult);
            //}
            //catch (Exception ex)
            //{
            //    return ResponseFactory.CreateError<string>(ex.Message);
            //}
        }
示例#5
0
 public static Response <string> HttpPutString(HttpParameters parameters)
 {
     return(HttpUploadString(parameters, WebRequestMethods.Http.Put));
 }
示例#6
0
 //Put
 public static Task <Response <T> > HttpPutAsync <T>(HttpParameters parameters)
 {
     return(UploadStringTaskAsync <T>(parameters, WebRequestMethods.Http.Put));
 }