当前位置: 首页>>代码示例>>C#>>正文


C# HttpRequestMessage.Dispose方法代码示例

本文整理汇总了C#中HttpRequestMessage.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.Dispose方法的具体用法?C# HttpRequestMessage.Dispose怎么用?C# HttpRequestMessage.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpRequestMessage的用法示例。


在下文中一共展示了HttpRequestMessage.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: sendGetRequest

        //public static string preServiceURI = "http://52.11.206.209/RESTFul/v1/";
        //public static string preServiceURI = "http://54.68.126.75/RESTFul/v1/";
        

        public static async Task<string> sendGetRequest(string methodName)
        {
            Random r = new Random();
            int x = r.Next(-1000000, 1000000);
            double y = r.NextDouble();
            double randomNumber = x + y;
            string ServiceURI = preServiceURI + methodName + "?xxx=" + randomNumber.ToString();
            HttpClient httpClient = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage();
            request.Method = HttpMethod.Get;
            request.RequestUri = new Uri(ServiceURI);
            request.Headers.Authorization = Windows.Web.Http.Headers.HttpCredentialsHeaderValue.Parse(Global.GlobalData.APIkey);
            //request.Headers.Authorization = Windows.Web.Http.Headers.HttpCredentialsHeaderValue.Parse("ce1fb637b7eee845c73b207d931bbc10");
            HttpResponseMessage response = await httpClient.SendRequestAsync(request);
            string returnString = await response.Content.ReadAsStringAsync();
            response.Dispose();
            httpClient.Dispose();
            request.Dispose();        
            return returnString;
            
        }
开发者ID:kleitz,项目名称:WPApp,代码行数:25,代码来源:RequestToServer.cs

示例2: Dispose_DisposeObject_ContentGetsDisposedAndSettersWillThrowButGettersStillWork

        public void Dispose_DisposeObject_ContentGetsDisposedAndSettersWillThrowButGettersStillWork()
        {
            var rm = new HttpRequestMessage(HttpMethod.Get, "http://example.com");
            var content = new MockContent();
            rm.Content = content;
            Assert.False(content.IsDisposed);

            rm.Dispose();
            rm.Dispose(); // Multiple calls don't throw.
            
            Assert.True(content.IsDisposed);
            Assert.Throws<ObjectDisposedException>(() => { rm.Method = HttpMethod.Put; });
            Assert.Throws<ObjectDisposedException>(() => { rm.RequestUri = null; });
            Assert.Throws<ObjectDisposedException>(() => { rm.Version = new Version(1, 0); });
            Assert.Throws<ObjectDisposedException>(() => { rm.Content = null; });

            // Property getters should still work after disposing.
            Assert.Equal(HttpMethod.Get, rm.Method);
            Assert.Equal(new Uri("http://example.com"), rm.RequestUri);
            Assert.Equal(_expectedRequestMessageVersion, rm.Version);
            Assert.Equal(content, rm.Content);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:22,代码来源:HttpRequestMessageTest.cs


注:本文中的HttpRequestMessage.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。