using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Com.FirmLib
{
    public class HttpClientManager
    {
        private static HttpClient m_HttpClient;
        public static void Clear()
        {
            if (m_HttpClient != null)
                m_HttpClient.Dispose();
            m_HttpClient = null;
        }
        /// <summary>
        /// 创建基础client
        /// </summary>
        /// <returns></returns>
        public static HttpClient CreateClient()
        {
            //服务器限制了连接数，还是本地httpClient不能使用多个，待查
            if (m_HttpClient != null)
            {

                //m_HttpClient.CancelPendingRequests();
               // m_HttpClient.Dispose();
               return m_HttpClient;
            }
            //WebRequestHandler handler = new WebRequestHandler();
            //handler.ReadWriteTimeout = 30000;
           
            //HttpClient client = new HttpClient(handler);
            HttpClient client = new HttpClient();
            client.Timeout = new TimeSpan(0, 0, 30);
           // client.DefaultRequestHeaders.ConnectionClose = true;
            //client.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36");
           
            //client.DefaultRequestHeaders.Add("cache-control", "no-cache");
            //client.DefaultRequestHeaders.Add("KeepAlive", "true");
            //client.DefaultRequestHeaders.Add("Connection", "Keep-Alive");
            //client.DefaultRequestHeaders.Add("Keep-Alive", "timeout=600");
            // client.DefaultRequestHeaders.Connection.Add("keep-alive");
            //client.pos
            return m_HttpClient =client;
           // return client;
        }
    }
}
