title: HttpWebRequest. The remote server returned an error: (500) Internal Server Error
body: <p>I need help with HttpWebRequest in C#. Below lines of codes are working fine for local IIS but when I upload to remote server, it starts to giving me "The remote server returned an error: (500) Internal Server Error.". I have try many variations with GET and POST method but unable to figure it out what is the problem. Please have a look into below code and let me know what is wrong with this.</p>
  
  <pre><code>try
  {
      string postData = "applicaitonid=abc&amp;deviceid=xyz";
      string uri = System.Configuration.ConfigurationManager.AppSettings.Get("baseUrl") + System.Configuration.ConfigurationManager.AppSettings.Get("ABApiPath") + "ConfirmAppBinding/?" + postData;
  
      System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(uri);
      request.Method = "POST"; // Set type Post
      //request.Method = "GET";
      request.UserAgent = Request.UserAgent.ToString();
      request.ContentType = @"application/json";
      request.MediaType = "application/json";
      request.Accept = "application/json";
      request.KeepAlive = false;
      request.ProtocolVersion = HttpVersion.Version11;
      //byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(postData);
      request.Timeout = 500000;             //Increase timeout for testing
  
      Stream reqstr = request.GetRequestStream();
      //reqstr.Write(buffer, 0, buffer.Length);
      reqstr.Close();
  
      // Read Response
      var httpResponse = request.GetResponse();
      using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
      {
          JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
          JsonMessage.message = streamReader.ReadToEnd();
          streamReader.Close();
      }
  }
  catch (WebException e)
  {
      JsonMessage.message = e.Message;
      return Json(JsonMessage, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>As I told you, I have used default GET method but it didn't solve the problem. </p>