title: the remote server error (401) Unauthorized while uploading a file using c#
body: <p>I am trying to upload a file to server but its giving me 401 error and here is my code. </p>
  
  <pre><code>static void Main(string[] args)
  {
      String key = "EwH6r-U61eveh4kjrx4QiZVjaNrU4QGZ";
      String input = @"E:\New folder\untitled_1.png";
      String output = @"E:\New folder (2)\untitled_1.png";
  
      String url = "https://api.tinify.com/shrink";
      WebClient client = new WebClient();
      //  HttpWebRequest client = (HttpWebRequest)WebRequest.Create(url);
      //  client.KeepAlive = false;
      // client.ContentType = "application/x-www-form-urlencoded";
      // client.Method = "POST";
      //  client.Timeout = System.Threading.Timeout.Infinite;
      //  client.Credentials = new NetworkCredential("?", "?");
      client.UseDefaultCredentials = false;
      String auth = Convert.ToBase64String(Encoding.UTF8.GetBytes("api:" + key));
      client.Headers.Add(HttpRequestHeader.Authorization, "Basic" + auth);
      //String input1 = @"key=GTThtXcEQ7shvgFL-aFy_W_tRNhHgMl3&amp;image=" + Convert.ToBase64String(File.ReadAllBytes(input));
      // String input3 = input1+auth;
      // byte[] bytes = Encoding.UTF8.GetBytes(input1);
      // Stream os = null;
      try
      {
          // client.ContentLength = bytes.Length;
          //  os = client.GetRequestStream();
          //  os.Write(bytes, 0, bytes.Length);
          client.UploadData(url, File.ReadAllBytes(input));
          // client.UploadFile(url, "POST", input);
          client.DownloadFile(client.ResponseHeaders["Location"], output);
      }
      catch (Exception e)
      {
          Console.WriteLine("compression failed " + e.Message);
      }
  
  }`
  </code></pre>