本文整理汇总了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;
}
示例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);
}