Advertisement
HotausTV

Program.cs

Apr 22nd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Threading;
  4. using System.Net;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Newtonsoft.Json;
  10.  
  11. namespace ConsoleApp6
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.  
  18.             HttpWebRequest req = HttpWebRequest.CreateHttp("http://httpbin.org/ip");
  19.             req.Method = "GET";
  20.             HttpWebResponse res = (HttpWebResponse)req.GetResponse();
  21.             using (Stream stream = res.GetResponseStream())
  22.             {
  23.                 StreamReader reader = new StreamReader(stream);
  24.                 String s = reader.ReadToEnd();
  25.                 Console.WriteLine(s);
  26.                
  27.  
  28.                 WebClient client = new WebClient();
  29.                 client.DownloadFile("http://httpbin.org/image/png", "plik.png");
  30.  
  31.                 client.DownloadFile("http://ipv4.download.thinkbroadband.com/5MB.zip", "plik.zip");
  32.                 Console.WriteLine("Skończono!");
  33.  
  34.                 client.DownloadFileAsync(new Uri("http://ipv4.download.thinkbroadband.com/5MB.zip"), "plik.zip");
  35.  
  36.                 client.DownloadFileCompleted += client_DownloadFileCompleted;
  37.                 Console.WriteLine("Dalszy ciąg programu...");
  38.                 evt.WaitOne();
  39.             }
  40. }
  41.             static ManualResetEvent evt = new System.Threading.ManualResetEvent(false);
  42.             static void client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
  43.             {
  44.                
  45.                 Console.WriteLine("Pobrano plik!");
  46.                 evt.Set();
  47.             }
  48.         }
  49.  
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement