本文整理汇总了C#中HttpClient.GetStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.GetStreamAsync方法的具体用法?C# HttpClient.GetStreamAsync怎么用?C# HttpClient.GetStreamAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient.GetStreamAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadXmlAsync
async void DownloadXmlAsync()
{
string url ="http://www2.meteogalicia.es/galego/observacion/estacions/contidos/DatosHistoricosXML_dezminutal.asp?est=10155¶m=2542,2548,2540,2541,2547,2545&data1=18/11/2015&data2=18/11/2015&idprov=2&red=102";
HttpClient client = new HttpClient();
Stream theStream = await client.GetStreamAsync(url);
StreamReader reader = new StreamReader(theStream, System.Text.Encoding.ASCII, false);
// procesarFicheroXml( reader )
}
示例2: SetAfterUse_Throws
public async Task SetAfterUse_Throws()
{
using (var handler = new HttpClientHandler())
using (var client = new HttpClient(handler))
{
handler.MaxResponseHeadersLength = int.MaxValue;
await client.GetStreamAsync(Configuration.Http.RemoteEchoServer);
Assert.Throws<InvalidOperationException>(() => handler.MaxResponseHeadersLength = int.MaxValue);
}
}
示例3: GetStreamAsync_ReadToEnd_Success
public async Task GetStreamAsync_ReadToEnd_Success()
{
var customHeaderValue = Guid.NewGuid().ToString("N");
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-ResponseStreamTest", customHeaderValue);
Stream stream = await client.GetStreamAsync(Configuration.Http.RemoteEchoServer);
using (var reader = new StreamReader(stream))
{
string responseBody = reader.ReadToEnd();
_output.WriteLine(responseBody);
// Calling GetStreamAsync() means we don't have access to the HttpResponseMessage.
// So, we can't use the MD5 hash validation to verify receipt of the response body.
// For this test, we can use a simpler verification of a custom header echo'ing back.
Assert.True(responseBody.Contains(customHeaderValue));
}
}