title: Exception throws bad request 400
body: <p>Please provide me some idea for a solution for this error-message:</p>
  
  <blockquote>
    <p>Exception throws bad request 400</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>public static T MakeRequestPost&lt;T&gt;(string requestUrl)
  {
      try
      {
          string postContent = requestUrl.Substring(requestUrl.IndexOf('?') + 1);
          string url = requestUrl.Substring(0, requestUrl.IndexOf('?'));
  
          HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
          request.Method = "POST";
          request.ContentLength = postContent.Length;
          request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
  
          using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
          {
              writer.Write(postContent, 0, postContent.Length);
          }
  
          using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
          {
              if (response.StatusCode != HttpStatusCode.OK)
                  throw new Exception(String.Format(
                     "Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription));
  
              DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(T));
              object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
              T jsonResponse = (T)objResponse;
              return jsonResponse;
          }
      }
      catch (Exception e)
      {
          Console.WriteLine(e.Message);
          return default(T);
      }
  }
  </code></pre>