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


C# HttpClient.GetStreamAsync方法代码示例

本文整理汇总了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&param=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 )

        }
开发者ID:Maldercito,项目名称:adat,代码行数:11,代码来源:1447840456$Form1.cs

示例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);
     }
 }
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:10,代码来源:HttpClientHandlerTest.MaxResponseHeadersLength.cs

示例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));
            }
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:18,代码来源:ResponseStreamTest.cs


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