title: Receiving The remote server returned an error: (403) Forbidden message
body: <p>I am receiving "The remote server returned an error: (403) Forbidden" error message on the block of code below.  Specifically this line is failing: <strong>var response = (HttpWebResponse)(request.GetResponse());</strong>   </p>
  
  <p>The code works perfectly on my dev machine, but not in production.  I am using IIS 7.5 in both environments.  Both machines are fulling patched (all Windows updates installed).  Using 4.0 .Net Framework.  Not sure why it works on one machine and not other other.  </p>
  
  <p>Code: </p>
  
  <pre><code>var uri = new Uri(url);
  var request = (HttpWebRequest)WebRequest.Create(uri);
  
  request.KeepAlive = false;
  request.ProtocolVersion = HttpVersion.Version10;
  request.Timeout = System.Threading.Timeout.Infinite;
  request.Method = @"POST";
  request.ContentType = @"application/x-www-form-urlencoded";
  request.ContentLength = postData.Length;
  request.UserAgent = @"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";                    
  request.Accept = "*/*";                    
  
  //setup the stream variables and do the send/retrieve of data
  Stream writeStream = request.GetRequestStream();
  var bytes = System.Text.Encoding.ASCII.GetBytes(postData);
  writeStream.Write(bytes, 0, bytes.Length);
  writeStream.Close();                    
  
  var response = (HttpWebResponse)(request.GetResponse());                    
  var responseStream = response.GetResponseStream();                    
  var readStream = new StreamReader(responseStream, Encoding.UTF8);                    
  pageResponse = readStream.ReadToEnd();
  </code></pre>