using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RestSharp;
using System.Net;
using Common;

namespace CommonEntity
{
    public class MyHttp
    {
        private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(MyHttp));
        /// <summary>
        /// 发送HTTP请求
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Url"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string SendHttpData<T>(string Url, T obj)
        {
            try
            {
                var A = (SecurityProtocolType)48;
                var B = (SecurityProtocolType)192;
                var C = (SecurityProtocolType)768;
                var D = (SecurityProtocolType)3072;
                var E = (SecurityProtocolType)12288;
                ServicePointManager.SecurityProtocol = A | B | C | D | E;
                var client1 = new RestClient(Url);
                var request1 = new RestRequest("", Method.POST);
                //var jsa= Newtonsoft.Json.JsonConvert.SerializeObject(obj);
                request1.AddJsonBody(obj);
                var QQQ = client1.Execute(request1);
                HttpStatusCode HHH = QQQ.StatusCode;
                string fanhuizhi = QQQ.Content;
                return fanhuizhi;
            }
            catch (Exception ex)
            {
                //string Key = "HttpRequest_" + resp.code + "_" + resp.roomNumber;
                //MemoryCacheHelper.Set(Key, 1, DateTimeOffset.Now.AddMinutes(10));
                logger.Error("Fault Push Error:" + ex.Message);
                logger.Error("Fault Push Error:" + ex.StackTrace);
                return ex.Message;
            }
        }
    }
}
