I'm stumped with this one. Here's the code
byte contentBytes = System.Text.Encoding.ASCII.GetBytes(content); HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(requestUrl); webRequest.Method = "POST"; webRequest.SendChunked = true; webRequest.ContentLength = contentBytes.Length; System.IO.Stream requestStream = webRequest.GetRequestStream(); requestStream.Write(contentBytes, 0, contentBytes.Length); requestStream.Close(); HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse();
I've tried closing the requestStream after the response but still the same exception when I GetResponse():
ProtocolViolationException: Content-Length or Chunked Encoding cannot be set for an operation that does not write data.
I'm clearly writing to the request stream, so what gives?
Thanks In Advance,
SteveWednesday, August 18, 2010 2:48 AM
This doesnt make sense. From your code, it appears you are doing everything right, (although setting both chunked and content-length is not needed, you should set one or the other). This exception you are getting (ProtocolViolationException) is very confusing. If the redirect (303) does not require content to be posted again, then the system.net library should have drained your content transparently. It should not be throwing this exception.
Can you get a repro with tracing enabled (see instructions in my signature) and post the trace log on pastebin.com and put a link here?
My blog (including System.Net topics
Instruction on how to create a tracelog with your System.Net application
System.Net Links and HOWTOsMonday, August 23, 2010 8:26 PM