示例#1
0
        protected override async Task <Stream> SendRemoteRequestInternalAsync()
        {
            IHttpWebRequest httpWebRequest = httpWebRequestFactory.Create("https://visualstudio-devdiv-c2s.msedge.net/ab");

            httpWebRequest.Method      = "GET";
            httpWebRequest.CachePolicy = DefaultCachePolicy;
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.AddHeaders(GetAllFilters());
            Stream stream = null;

            try
            {
                CancellationTokenSource tokenSource = new CancellationTokenSource();
                Task.Delay(60000).ContinueWith(delegate
                {
                    tokenSource.Cancel();
                });
                IHttpWebResponse httpWebResponse = await httpWebRequest.GetResponseAsync(tokenSource.Token).ConfigureAwait(false);

                if (httpWebResponse.ErrorCode != 0)
                {
                    return(stream);
                }
                stream = httpWebResponse.GetResponseStream();
                return(stream);
            }
            catch
            {
                return(stream);
            }
        }