コード例 #1
0
        private System.Net.Http.HttpClient CreateHTTPClient(string clientIPAddress)
        {
            System.Net.Http.HttpClient httpClient;

            if (remoteCertificateValidationCallback == null)
            {
                httpClient = new System.Net.Http.HttpClient();
            }
            else
            {
#if NET45 || NET46 || NET47
                // special handling for .NET 4.5 & 4.6, since the HttpClientHandler does not have the ServerCertificateValidationCallback
                System.Net.Http.WebRequestHandler webRequestHandler = new System.Net.Http.WebRequestHandler();
                webRequestHandler.ServerCertificateValidationCallback += remoteCertificateValidationCallback;
                httpClient = new System.Net.Http.HttpClient(webRequestHandler, true);
#else
                System.Net.Http.HttpClientHandler httpClientHandler = new System.Net.Http.HttpClientHandler
                {
                    ServerCertificateCustomValidationCallback = remoteCertificateValidationCallback.Invoke
                };
                httpClient = new System.Net.Http.HttpClient(httpClientHandler, true);
#endif
            }

            if (clientIPAddress != null)
            {
                httpClient.DefaultRequestHeaders.Add("X-Client-IP", clientIPAddress);
            }

            return(httpClient);
        }
コード例 #2
0
        private System.Net.Http.HttpClient CreateHttpClient()
        {
            var webRequestHandler = new System.Net.Http.WebRequestHandler();

            webRequestHandler.ServerCertificateValidationCallback += configuration.SslTrustManager.ServerCertificateValidationCallback;
            return(new System.Net.Http.HttpClient(webRequestHandler, true));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: kiewic/Projects
        private static async void Foo()
        {
            Uri uri = new Uri("http://localhost/?cache=1");

            System.Net.Http.WebRequestHandler handler =
                new System.Net.Http.WebRequestHandler();

            // Cache options:
            //     System.Net.Cache.RequestCacheLevel.BypassCache
            //     System.Net.Cache.RequestCacheLevel.CacheIfAvailable
            handler.CachePolicy = new System.Net.Cache.RequestCachePolicy(
                System.Net.Cache.RequestCacheLevel.CacheIfAvailable);

            System.Net.Http.HttpClient client2 =
                new System.Net.Http.HttpClient(handler);

            System.Net.Http.HttpResponseMessage response2 = await client2.GetAsync(uri);
            response2.EnsureSuccessStatusCode();
            string str = await response2.Content.ReadAsStringAsync();
            Console.WriteLine(str);

            System.Threading.Thread.Sleep(1111);

            response2 = await client2.GetAsync(uri);
            response2.EnsureSuccessStatusCode();
            str = await response2.Content.ReadAsStringAsync();
            Console.WriteLine(str);

            autoResetEvent.Set();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: DaveCS1/Projects
        private static async void Foo()
        {
            Uri uri = new Uri("http://localhost/?cache=1");

            System.Net.Http.WebRequestHandler handler =
                new System.Net.Http.WebRequestHandler();

            // Cache options:
            //     System.Net.Cache.RequestCacheLevel.BypassCache
            //     System.Net.Cache.RequestCacheLevel.CacheIfAvailable
            handler.CachePolicy = new System.Net.Cache.RequestCachePolicy(
                System.Net.Cache.RequestCacheLevel.CacheIfAvailable);

            System.Net.Http.HttpClient client2 =
                new System.Net.Http.HttpClient(handler);

            System.Net.Http.HttpResponseMessage response2 = await client2.GetAsync(uri);

            response2.EnsureSuccessStatusCode();
            string str = await response2.Content.ReadAsStringAsync();

            Console.WriteLine(str);

            System.Threading.Thread.Sleep(1111);

            response2 = await client2.GetAsync(uri);

            response2.EnsureSuccessStatusCode();
            str = await response2.Content.ReadAsStringAsync();

            Console.WriteLine(str);

            autoResetEvent.Set();
        }
コード例 #5
0
        public async Task <TwitterGnip.SearchApi.Response.SearchResponse> GetTweetFromUser(string twitterUsername)
        {
            TwitterGnip.SearchApi.Response.SearchResponse result = null;
            System.Net.ServicePointManager.Expect100Continue = false;
            using (System.Net.Http.WebRequestHandler httpHandler = new System.Net.Http.WebRequestHandler()
            {
                AutomaticDecompression = System.Net.DecompressionMethods.Deflate | System.Net.DecompressionMethods.GZip,
            }
                   )
            {
                using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(httpHandler))
                {
                    TwitterGnip.SearchApi.Request.SearchRequest request = new Request.SearchRequest()
                    {
                        query = "from: [REPLACE]"
                    };
                    string jsonRequest = Newtonsoft.Json.JsonConvert.SerializeObject(request);
                    System.Net.Http.StringContent strContent = new System.Net.Http.StringContent(jsonRequest);
                    strContent.Headers.Add("Authorization", string.Format("Basic: {0}", AuthInfo));
                    strContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    var response = await client.PostAsync(SearchApiEndPoint, strContent);

                    if (response.IsSuccessStatusCode)
                    {
                        var jsonResponse = await response.Content.ReadAsStringAsync();

                        result = Newtonsoft.Json.JsonConvert.DeserializeObject <TwitterGnip.SearchApi.Response.SearchResponse>(jsonResponse);
                    }
                    else
                    {
                        throw new Exception(response.ReasonPhrase);
                    }
                }
            }
            return(result);
        }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: jrwren/XBMCRemote
 public StatusUpdateHandler(Action<string> a)
     : base(new System.Net.Http.WebRequestHandler())
 {
     this.a = a;
     this.webRequestHandler = base.InnerHandler as System.Net.Http.WebRequestHandler;
 }