private Task<string> UploadStringAsync(string method, IProgress<string> progress)
        {
            return Task.Run(() =>
                {
                    using (var client = new WebClient())
                    {
                        var address = restClient.PrepareUri();

                        restClient.SetHeaders(client);
                        
                        client.TraceRequest(address, method, data, progress);

                        var watch = new Stopwatch();
                        watch.Start();
                        client.UploadString(address, method, data);
                        watch.Stop();
                        
                        client.TraceResponse(address,
                                             method,
                                             string.Format(CultureInfo.InvariantCulture,
                                                           "Completed in {0} seconds",
                                                           watch.Elapsed.TotalSeconds),
                                             progress);
                    }

                    return "Done";
                });
        }
Exemplo n.º 2
0
        private async Task<string> DownloadStringAsync(IProgress<string> progress)
        {
            using (var client = new WebClient())
            {
                var address = PrepareUri();
                SetHeaders(client);


                client.TraceRequest(address, "GET", progress);

                var responseString = await client.DownloadStringTaskAsync(address)
                                                 .ConfigureAwait(false);

                client.TraceResponse(address, "GET", responseString, progress);

                return responseString;
            }
        }
Exemplo n.º 3
0
        private async Task<Stream> DownloadStreamAsync(IProgress<string> progress)
        {
            var downloadTask = Task.Run(() =>
                {
                    using (var client = new WebClient())
                    {
                        var address = PrepareUri();

                        SetHeaders(client);

                        client.TraceRequest(address, "GET", progress);

                        var bytes = client.DownloadData(address);

                        client.TraceResponse(address, "GET", "Length=" + bytes.Length, progress);

                        return new MemoryStream(bytes);
                    }
                }).ConfigureAwait(false);

            return await downloadTask;
        }