title: webrequest get throws an exception "The remote server returned an error: (501) Not Implemented."
body: <p>I'm trying to load a file using webrequest method.  First I need to log in then get a file or a directory listing. <a href="https:///xxx.yyy.zzz/login_template" rel="nofollow">https:///xxx.yyy.zzz/login_template</a></p>
  
  <p>When I look at the website source in firefox, I see</p>
  
  <pre><code>  &lt;META http-equiv="Content-Type" content="text/html"&gt;
    ....
    &lt;form method="post" action="/template/login" enctype="application/x-www-form- urlencoded"&gt;
    ....
    &lt;input name="user" type="text"&gt;
    &lt;input name="password" type="password"&gt;
    &lt;input type=hidden name="switch" value="Log In"&gt;
    &lt;input type="submit" value="Accept"&gt;
  </code></pre>
  
  <p>So, I wrote this code:</p>
  
  <pre><code>  public static string DownloadFile()
    {
       CookieContainer cookieJar = new CookieContainer();
       HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https:///xxx.yyy.zzz/login_template");
       request.CookieContainer = cookieJar;
  
       // Set the credentials.
       request.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
       request.Credentials = new NetworkCredential(userName, pass);
       request.KeepAlive = true;
       request.UserAgent = "SecureTransport";
       request.ContentType = @"application/x-www-form-urlencoded";
       request.Method = WebRequestMethods.Http.Post;
  
       bool loggedin = false;
       try
       {
           // first need to log in
           string postData = "user=" + userName + "&amp;Password=" + pass;
           byte[] postBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(postData);
           request.ContentLength = postBuffer.Length;
           Stream newStream = request.GetRequestStream();
           // Send the data.
           newStream.Write(postBuffer, 0, postBuffer.Length);
           newStream.Close();
  
           using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
           {
               // Get the stream containing content returned by the server.
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    loggedin = true;
                }
                response.Close();
            }
  </code></pre>
  
  <p>The response that I get is OK - so it seems that I successfully logged in.
  But then, I need to go to another url to get a file <a href="https:///xxx.yyy.zzz/myfile.zip" rel="nofollow">https:///xxx.yyy.zzz/myfile.zip</a></p>
  
  <pre><code> HttpWebRequest requestToGetFile = (HttpWebRequest)WebRequest.Create("https:///xxx.yyy.zzz/myfile.zip");
   requestToGetFile.Method = WebRequestMethods.Http.Get;
   requestToGetFile.CookieContainer = cookieJar;
  
   requestToGetFile.UserAgent = "SecureTransport";
   requestToGetFile.ContentType = @"application/octet-stream";
   using (HttpWebResponse responseToGetFile = (HttpWebResponse)requestToGetFile.GetResponse())
   {
      if (responseToGetDir.StatusCode != HttpStatusCode.OK)
      {    
         ...
      }
   }
  </code></pre>
  
  <p>I always get an exception System.Exception: System.Net.WebException: The remote server returned an error: (501) Not Implemented. at System.Net.HttpWebRequest.GetResponse()</p>
  
  <p>I've read all I could find about this error - and it seems that the problem should be in the way I do get - there is something in the request that it's not being handled properly on the server - but I don't see what is wrong. </p>