Facebook
From Bistre Coyote, 8 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 403
  1.  
  2.     internal class Program
  3.     {
  4.         private static void Main(string[] args)
  5.         {
  6.             using (var client = new HttpClient())
  7.             using (var content = new MultipartFormDataContent())
  8.             {
  9.                 // Make sure to change API address
  10.                 client.BaseAddress = new Uri("http://localhost:53798/");
  11.  
  12.                 // Add first file content
  13.                 var fileContent1 =
  14.                     new ByteArrayContent(File.ReadAllBytes(@"C:\temp\file.zip"));
  15.                 fileContent1.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
  16.                 {
  17.                     FileName = "test.zip"
  18.                 };
  19.  
  20.            
  21.  
  22.                 content.Add(fileContent1);
  23.  
  24.                 // Make a call to Web API
  25.                 content.Headers.Add("encryptedPassword", "haslo123123");
  26.                 content.Headers.Add("imei", "123");
  27.                 content.Headers.Add("pseudoUdid", "1");
  28.                 content.Headers.Add("versionCode", "1");
  29.                 var result = client.PostAsync("http://api.idcopy.hostingasp.pl/api/document/post", content).Result;
  30.  
  31.                 System.Console.ReadLine();
  32.             }
  33.         }
  34.     }