Reputation: 4985
This is a goofy question but I'm testing a tool and need to create an unusual situation. I want to make a POST request that sends several megabytes of data to a web server but I don't want the Content-Length set. (It would be OK if it was set to 0 or -1.)
HttpWebRequest automatically sets request.ContentLength to the length of the RequestStream buffer. Is there a way to prevent or circumvent this?
Upvotes: 3
Views: 1664
Reputation: 657
You can send a POST request without setting the Content-Length header by using chunked encoding. With chunked encoding, you send the data in segments (or "chunks") instead of in a single piece. This is useful when you need to send data to a server but you don't know the size.
Chunked encoding is part of HTTP 1.1 as defined by RFC 2616
.NET provides the SendChunked feature to support this scenario
Upvotes: 3