Posting with Content-Length


I’m trying to do an HTTP POST to a REST service (.NET Web Api) that doesn’t work well with chunked transfer encoding. Does anyone have a working example of sending an HTTP POST with the Content-Length header specified?

There are a large number of posts here regarding the topic, but I’ve not seen one where someone managed to get non-chunked transfers to work.

Session channel is openened like this:

_sessionChannel = wip_HTTPClientCreateOpts (NULL, NULL,
	//WIP_COPT_HTTP_VERSION, wip_httpVersion_e::WIP_HTTP_VERSION_1_0,
	WIP_COPT_HTTP_HEADER, "User-Agent", "WIP-HTTP-Client/1.0",

Data channel like this:

_dataChannel = wip_getFileOpts (_sessionChannel, const_cast<ascii*> (_url.c_str ()),
	 HttpClient::HttpClientImpl::HttpEventHandler, this,
	 //WIP_COPT_HTTP_VERSION, wip_httpVersion_e::WIP_HTTP_VERSION_1_0,
	 WIP_COPT_HTTP_HEADER, "Accept", _contentType,
	 WIP_COPT_HTTP_HEADER, "Content-Type", _contentType,
	 //WIP_COPT_HTTP_HEADER, "Content-Length", _requestData.size(),

I have tried to use HTTP version 1.0, as some people reported having more success with that. This did not work at all.
I’ve tried to use WIP_COPT_HTTP_DATA_ENCOD, but the channel is then not opened.
I tried using the various options with wip_HTTPClientCreateOpts and wip_getFileOpts, but no combination seems to work.
Specifying Content-Length always causes an HTTP 400 error. I also tried sending the Content-Length as a string, but with the same result.

I do call wip_shutdown after all data is written. The amount of data is small, typically 40-50 bytes, so it is written in one go with wip_write.

Any ideas?


I’ve had it working fine for me in a couple of situations.

Biggest issue is making sure that the size is correct. You have to make sure that you count cr and lf characters correctly.

I’ll have a look at work tomorrow and see how I did it…

Ciao, Dave

You can tell me specifically what you are doing. Because maybe I will help you