title: Getting error response using web request
body: <p>I am using below code for send XML file to server, if I upload <code>adduser.xml</code> (this is using for adding users) I am getting success response, but for <code>deleteuser.xml</code> (this is user for delete the user) I am getting </p>
  
  <blockquote>
    <p><em>The remote server returned an error: (400)<br>
    Bad Request. at System.Net.HttpWebRequest.GetResponse()<br>
    at DeleteUser.Page_Load(Object sender, EventArgs e)</em></p>
  </blockquote>
  
  <p>I have tried method types <code>PUT</code>, <code>GET</code>, <code>POST</code> and <code>DELETE</code> but got the same error.</p>
  
  <p>Can you plz help me what I am doing wrong?</p>
  
  <pre><code> public partial class DeleteUser : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
              WebRequest req = null;
              WebResponse rsp = null;
              try
              {
                  string fileName = Server.MapPath("~/deleteuser.xml");
                  string uri = "http://test.com/AuctionUsers/delete";
                  req = WebRequest.Create(uri);
                  req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
                  req.Method = "POST";   
  
                  req.ContentType = "application/xml";     // content type
  
                  // Wrap the request stream with a text-based writer
                  StreamWriter writer = new StreamWriter(req.GetRequestStream());
                  // Write the XML text into the stream
                  writer.WriteLine(this.GetTextFromXMLFile(fileName));
                  writer.Close();
                  // Send the data to the webserver
  
                  rsp = req.GetResponse(); //I am getting error over here
                  StreamReader sr = new StreamReader(rsp.GetResponseStream());
                  string result = sr.ReadToEnd();
                  sr.Close();
                  Response.Write(result);
  
              }
              catch (WebException webEx)
              {
                  Response.Write(webEx.Message.ToString());
                  Response.Write(webEx.StackTrace.ToString());
              }
              catch (Exception ex)
              {
                  Response.Write(ex.Message.ToString());
                  Response.Write(ex.StackTrace.ToString());
              }
              finally
              {
                  if (req != null) req.GetRequestStream().Close();
                  if (rsp != null) rsp.GetResponseStream().Close();
              }
          }
  
          private string GetTextFromXMLFile(string file)
          {
              StreamReader reader = new StreamReader(file);
              string ret = reader.ReadToEnd();
              reader.Close();
              return ret;
          }
      }
  </code></pre>
  
  <p>Thank you in advance.</p>