title: I'm facing the error Stream.Length throws NotSupportedException
body: <p>I am trying to POST some data from ASP.Net application to PHP using <code>HttpWebRequest</code> object. But when I try reading the <code>Request</code> content using </p>
  
  <pre><code>Stream myStream = myWebReq.GetRequestStream();
  </code></pre>
  
  <p>I am getting an error </p>
  
  <blockquote>
    <p>'responseStream.Length' threw an exception of type 'System.NotSupportedException'.<br>
    Length = 'dataStream.Length' threw an exception of type 'System.NotSupportedException'<br>
    Position = 'dataStream.Position' threw an exception of type 'System.NotSupportedException'  </p>
  </blockquote>
  
  <p>Here is the code</p>
  
  <pre><code>string strURL = null;
  HttpWebRequest myWebReq = default(HttpWebRequest);
  HttpWebResponse myWebResp = default(HttpWebResponse);
  
  byte[] byteData = null;
  StreamReader sr = default(StreamReader);
  strURL = "http://people.com.pk/nppm/hrms_ppm_service.php?dump=1";
  myWebReq = (HttpWebRequest)WebRequest.Create(strURL);
  myWebReq.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
  myWebReq.Method = "POST";
  
  Label1.Text = Newtonsoft.Json.JsonConvert.SerializeObject(batches).ToString();
  
  byteData = UTF8Encoding.UTF8.GetBytes(Label1.Text);
  myWebReq.ContentLength = byteData.Length;
  
  myWebReq.KeepAlive = true;
  
  if (myWebReq.Proxy != null)
  {
     myWebReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
  }
  
  Stream myStream = myWebReq.GetRequestStream();
  
  if (byteData.Length &gt; 0)
  {
     myStream.Write(byteData, 0, byteData.Length);
     myStream.Close();
  }
  
  myWebResp = (HttpWebResponse)myWebReq.GetResponse();
  sr = new StreamReader(myWebResp.GetResponseStream());
  string strJSON__2 = sr.ReadToEnd();
  Label1.Text = strJSON__2;
  </code></pre>