Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Threading;
- using System.Net;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Newtonsoft.Json;
- namespace ConsoleApp6
- {
- class Program
- {
- static void Main(string[] args)
- {
- HttpWebRequest req = HttpWebRequest.CreateHttp("http://httpbin.org/ip");
- req.Method = "GET";
- HttpWebResponse res = (HttpWebResponse)req.GetResponse();
- using (Stream stream = res.GetResponseStream())
- {
- StreamReader reader = new StreamReader(stream);
- String s = reader.ReadToEnd();
- Console.WriteLine(s);
- WebClient client = new WebClient();
- client.DownloadFile("http://httpbin.org/image/png", "plik.png");
- client.DownloadFile("http://ipv4.download.thinkbroadband.com/5MB.zip", "plik.zip");
- Console.WriteLine("Skończono!");
- client.DownloadFileAsync(new Uri("http://ipv4.download.thinkbroadband.com/5MB.zip"), "plik.zip");
- client.DownloadFileCompleted += client_DownloadFileCompleted;
- Console.WriteLine("Dalszy ciąg programu...");
- evt.WaitOne();
- }
- }
- static ManualResetEvent evt = new System.Threading.ManualResetEvent(false);
- static void client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
- {
- Console.WriteLine("Pobrano plik!");
- evt.Set();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement