title: C# 405 methods not allowed
body: <p>I am posting data to a website and displaying the resulting json data,
  This is the function I ended up with after taking some pieces from msdn's example</p>
  
  <pre><code>        private string request(string url, string data)
          {
              byte[] byteArray;
  
              string postData,
                      responseFromServer;
  
              WebResponse response;
  
              Stream dataStream;
  
              StreamReader reader;
  
              HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
              request.Proxy = new WebProxy(ip, port);
  
              responseFromServer = string.Empty;
              request.Method = "POST";
              request.Timeout = 10000;
  
              postData = data;
              byteArray = Encoding.UTF8.GetBytes(postData);
  
              request.ContentType = "application/x-www-form-urlencoded";
              request.ContentLength = byteArray.Length;
  
              try
              {
                  dataStream = request.GetRequestStream();
                  dataStream.Write(byteArray, 0, byteArray.Length);
                  dataStream.Close();
  
                  response = request.GetResponse();
                  dataStream = response.GetResponseStream();
  
                  reader = new StreamReader(dataStream);
  
                  responseFromServer = reader.ReadToEnd();
  
                  reader.Close();
                  dataStream.Close();
                  response.Close();
              }
              catch (Exception x)
              {
                  x.ToString();
              }
  
  
              return responseFromServer;
          }
      }
  </code></pre>
  
  <p>The ip and port variables are within the class that this function is inside of.
  When GetResponse() is called, it this exception.</p>
  
  <blockquote>
    <p>{System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.</p>
  </blockquote>
  
  <p>Ive tested it and it is only because of the proxy, but the parameters are correct.
  Why is this exception being thrown?</p>