title: Webclient POST 405 Error in API
body: <p>I've written some code a while back that handles <code>POST</code> requests. Suddenly it stopped working whilst I changed nothing in either the API (It still works fine with postman) nor the <strong>C#</strong> code. But I get a <code>405</code> error (method not allowed) when I run my code.
  The login method:</p>
  
  <pre><code>public byte[] logInViaAPI(string email, string password)
          {
              var response = APIHandler.Post("http://myurlhere", new NameValueCollection() {
                  {   "email", email          },
                  {   "password", password    },
              });
              return response;
          }
  </code></pre>
  
  <p>This is my POST method:</p>
  
  <pre><code>public static byte[] Post(string uri, NameValueCollection pairs)
          {
              byte[] response = null;
              try
              {
                  using (WebClient client = new WebClient())
                  {
  
                      response = client.UploadValues(uri, pairs); //This is where I get my error
                  }
              }
              catch (WebException ex)
              {
                  Console.Write(ex);
                  return null;
              }
              return response;
          }
  </code></pre>
  
  <p>The error: </p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.Net.WebException' occurred in
    System.dll</p>
  </blockquote>
  
  <p>Additional information: </p>
  
  <blockquote>
    <p>The remote server returned an error: (405) Method Not Allowed.</p>
  </blockquote>
  
  <p>I used <a href="https://stackoverflow.com/questions/4015324/http-request-with-post">HTTP request with post</a> as a source (and some other topics too) but I cant seem to figure out the problem.</p>