예제 #1
0
        public async Task <byte[]> PostAsync(Uri url, string parameters)
        {
#if DEBUG
            var cached = TestingEnvCore.GetUrlBytes(url, parameters);
            if (cached != null)
            {
                return(cached);
            }
#endif
            try
            {
                using (var webClient = new WebClient())
                {
                    webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    var data = Encoding.Default.GetBytes(parameters);

                    var result = await webClient.UploadDataTaskAsync(url, data);

#if DEBUG
                    TestingEnvCore.StoreUrlBytes(url, parameters, result);
#endif

                    return(result);
                }
            }
            catch (Exception e)
            {
                _logger.Exception(e);
                return(null);
            }
        }
예제 #2
0
        public async Task <byte[]> GetAsync(Uri url)
        {
#if DEBUG
            var cached = TestingEnvCore.GetUrlBytes(url);
            if (cached != null)
            {
                return(cached);
            }
#endif

            try
            {
                using (var webClient = new WebClient())
                {
                    var result = await webClient.DownloadDataTaskAsync(url);

#if DEBUG
                    TestingEnvCore.StoreUrlBytes(url, null, result);
#endif
                    return(result);
                }
            }
            catch (Exception e)
            {
                _logger.Exception(e);
                return(null);
            }
        }