Exemplo n.º 1
0
        private static string CommonProcess(CommonRequestArgs commonRequestArgs, Func <HttpClient, Byte[]> func)
        {
            var handler = new HttpClientHandler()
            {
                UseCookies = true
            };

            using (HttpClient client = new HttpClient(handler))
            {
                if (commonRequestArgs.Headers != null)
                {
                    foreach (KeyValuePair <string, string> header in commonRequestArgs.Headers)
                    {
                        client.DefaultRequestHeaders.Add(header.Key, header.Value);
                        client.DefaultRequestHeaders.Add("Connection", "Keep-Alive");
                        client.DefaultRequestHeaders.Add("Keep-Alive", "timeout=600");
                    }
                }
                if (commonRequestArgs.Timeout > 0)
                {
                    client.Timeout = new TimeSpan(0, 0, commonRequestArgs.Timeout);
                }
                Byte[] bytes = func(client);
                return(Encoding.UTF8.GetString(bytes));
            }
        }
Exemplo n.º 2
0
 private static string CommonProcess(CommonRequestArgs commonRequestArgs, Func <HttpClient, Byte[]> func)
 {
     using (HttpClient client = new HttpClient())
     {
         if (commonRequestArgs.Headers != null)
         {
             foreach (KeyValuePair <string, string> header in commonRequestArgs.Headers)
             {
                 client.DefaultRequestHeaders.Add(header.Key, header.Value);
             }
         }
         if (commonRequestArgs.Timeout > 0)
         {
             client.Timeout = new TimeSpan(0, 0, commonRequestArgs.Timeout);
         }
         Byte[] bytes = func(client);
         return(Encoding.UTF8.GetString(bytes));
     }
 }