title: Trouble with direct download links from Mediafire
body: <p>I had trouble downloading a file from Mediafire. I found out the I have to use their API. I found another SO question: <a href="https://stackoverflow.com/questions/4640176/get-direct-download-link-and-file-site-from-mediafire-com">"<em>Get direct download link and file site from Mediafire.com</em>"</a></p>
  
  <p>With the help of the shown functions I created the following class:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Mediafireclass mf = new Mediafireclass();
          WebClient webClient = new WebClient();
  
          mf.Mediafiredownload("somemediafirelink/test.txt");
          webClient.DownloadFileAsync(new Uri("somemediafirelink/test.txt"), @"location to save/test.txt"); 
      }
  
  }
  </code></pre>
  
  <p>and used the function by T3KBAU5 like this:</p>
  
  <pre><code>internal class Mediafireclass
  {
      public string Mediafiredownload(string download)
      {
          HttpWebRequest req;
          HttpWebResponse res;
          string str = "";
          req = (HttpWebRequest)WebRequest.Create(download);
          res = (HttpWebResponse)req.GetResponse();
          str = new StreamReader(res.GetResponseStream()).ReadToEnd();
          int indexurl = str.IndexOf("http://download");
          int indexend = GetNextIndexOf('"', str, indexurl);
          string direct = str.Substring(indexurl, indexend - indexurl);
          return direct;
      }
  
      private int GetNextIndexOf(char c, string source, int start)
      {
          if (start &lt; 0 || start &gt; source.Length - 1)
          {
              throw new ArgumentOutOfRangeException();
          }
          for (int i = start; i &lt; source.Length; i++)
          {
              if (source[i] == c)
              {
                  return i;
              }
          }
          return -1;
      }
  }
  </code></pre>
  
  <p>But when I run it this error pops up:
  <a href="https://i.stack.imgur.com/ATgmt.png" rel="nofollow noreferrer">Screenshot of the Error</a></p>
  
  <p>What can I do to solve the problem, and can you explain what this error means?</p>