Good morning. I am trying through WebRequest to send a json using the PUT method. When I get to httpWebRequest.GetResponse () I get an error.
You must write ContentLength bytes in the request flow before calling [Begin] GetResponse.
Writing the length property to the StreamWriter as in the posotion property gives me an exception.
'(writer.BaseStream) .length' produced an exception of type 'System.NotSupportedException' '(writer.BaseStream) .position' produced an exception of type 'System.NotSupportedException'
How could I fill in the length and position.
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(apiUrl);
httpWebRequest.ContentType = metodo.ContentType;
httpWebRequest.Method = WebRequestMethods.Http.Put;
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
string jsonData = jsSerializer.Serialize(datosPUT);
byte[] arrData = Encoding.UTF8.GetBytes(jsonData);
httpWebRequest.ContentLength = arrData.Length;
httpWebRequest.Expect = "application/json";
StreamWriter writer = new StreamWriter(httpWebRequest.GetRequestStream());
writer.Write(arrData);
writer.Close()
var response = (HttpWebResponse)httpWebRequest.GetResponse(); //AQUÍ EL ERROR