本文整理汇总了C#中System.Net.Http.HttpClient.GetInputStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.GetInputStreamAsync方法的具体用法?C# HttpClient.GetInputStreamAsync怎么用?C# HttpClient.GetInputStreamAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpClient
的用法示例。
在下文中一共展示了HttpClient.GetInputStreamAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenConnection
public async Task<bool> OpenConnection(Uri uri, TimeSpan? timeout = null)
{
if (uri == null)
{
throw new ArgumentNullException();
}
if (state != ConnectionState.Closed)
{
return true;
}
state = ConnectionState.TryingConnection;
#if WINDOWS_PHONE_APP||WINDOWS_APP||NETFX_CORE
var filter = new HttpBaseProtocolFilter();
filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.MostRecent;
var httpClient = new HttpClient(filter);
#else
var httpClient = new HttpClient(new WebRequestHandler
{
CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore),
});
#endif
var to = (timeout == null) ? TimeSpan.FromMilliseconds(DEFAULT_REQUEST_TIMEOUT) : timeout;
StartTimer((int)to.Value.TotalMilliseconds, httpClient);
try
{
#if WINDOWS_PHONE_APP||WINDOWS_APP||NETFX_CORE
var str = await httpClient.GetInputStreamAsync(uri);
#else
var str = await httpClient.GetStreamAsync(uri);
#endif
state = ConnectionState.Connected;
var task = Task.Factory.StartNew(() =>
{
#if WINDOWS_PHONE_APP||WINDOWS_APP||NETFX_CORE
using (var core = new StreamAnalizer(str.AsStreamForRead()))
#else
using (var core = new StreamAnalizer(str))
#endif
{
core.RunFpsDetector();
core.JpegRetrieved = (packet) => { OnJpegRetrieved(new JpegEventArgs(packet)); };
core.PlaybackInfoRetrieved = (packet) => { OnPlaybackInfoRetrieved(new PlaybackInfoEventArgs(packet)); };
core.FocusFrameRetrieved = (packet) => { OnFocusFrameRetrieved(new FocusFrameEventArgs(packet)); };
while (state == ConnectionState.Connected)
{
try
{
core.ReadNextPayload();
}
catch (Exception e)
{
Log("Caught " + e.GetType() + ": finish reading loop");
break;
}
}
}
Log("End of reading loop");
OnClosed(null);
});
return true;
}
catch (Exception)
{
return false;
}
}