0

I have written below code -

HttpWebRequest lHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
      lHttpWebRequest.Method = "POST";
      lHttpWebRequest.Headers.Add("Accept-Encoding", "gzip,deflate");

      lHttpWebRequest.ContentType = "text/xml";
      lHttpWebRequest.KeepAlive = false;

ASCIIEncoding lEnCoding = new ASCIIEncoding();

      byte[] lData = lEnCoding.GetBytes(xmlDocument.InnerXml);
      lHttpWebRequest.ContentLength = lData.Length;
HttpWebResponse lHttpWebResponse = (HttpWebResponse)lHttpWebRequest.GetResponse();

I am getting error -

You must provide a request body if you set ContentLength>0 or SendChunked==true.  Do this by calling [Begin]GetRequestStream before [Begin]GetResponse.

I am getting error at last line -

  HttpWebResponse lHttpWebResponse = (HttpWebResponse)lHttpWebRequest.GetResponse();
C Sharper
  • 8,284
  • 26
  • 88
  • 151

1 Answers1

0

I Added -

  ASCIIEncoding lEnCoding = new ASCIIEncoding();

  byte[] lData = lEnCoding.GetBytes(xmlDocument.InnerXml);
  lHttpWebRequest.ContentLength = lData.Length;

  using (Stream requestStream = lHttpWebRequest.GetRequestStream())
  {
    requestStream.Write(lData, 0, lData.Length);
    requestStream.Close();
  }

This worked.

C Sharper
  • 8,284
  • 26
  • 88
  • 151