Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Content-Length vs. Transfer-Encoding: chunked

558 views
Skip to first unread message

StdNet Dev

unread,
Aug 18, 2005, 4:34:25 PM8/18/05
to
WinHTTP seems to always send a Content-Length header.
This conflicts with Transfer-Encoding: chunked, which is necessary
in my application because it posts huge amounts of data, the
length of which is not known at the beginning of the post.

Windows 2000 IIS doesn't mind this, but Windows 2003 (IIS 6)
rejects the request if it sees both headers.

Is there a way to suppress the sending of Content-Length?

Thanks.

Mark Riordan


Stephen Sulzer

unread,
Aug 22, 2005, 3:44:50 AM8/22/05
to
WinHTTP provides no support for sending requests in the "Transfer-Encoding:
chunked" format. (It does support receiving responses that are in the
chunked format, though.) So WinHTTP will always set the Content-Length
request header.

There is no official way to suppress the Content-Length request header,
although it might be possible with the following hack (which I have not
tried):
-- register a status callback function on the request handle using
WinHttpSetStatusCallback, specifying at least
WINHTTP_CALLBACK_FLAG_CONNECT_TO_SERVER for the dwNotificationFlags
parameter
-- disable the keep-alive feature or set a "Connection: Close" request
header
-- use WinHttpWriteData to send your POST data (which I suspect you are
already doing); do not supply all of your POST data in a single buffer to
WinHttpSendRequest
-- during WinHttpSendRequest, when your callback gets the
CONNECTED_TO_SERVER notification, call:
WinHttpAddRequestHeaders(hRequest, L"Content-Length:", -1L,
WINHTTP_ADDREQ_FLAG_REPLACE);

The goal of this hack is to erase the Content-Length request header just
before WinHTTP sends the HTTP request.

- Stephen


0 new messages