# Posting with Content-Length

**URL:** <https://forum.sierrawireless.com/t/posting-with-content-length/7779>\
**Category:** Open AT\
**Created:** [February 26, 2015, 7:53am UTC](https://forum.sierrawireless.com/t/posting-with-content-length/7779 "2015-02-26T07:53:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierreandre](https://avatars.discourse-cdn.com/v4/letter/p/58f4c7/32.png) [@pierreandre](https://forum.sierrawireless.com/u/pierreandre)\
**Post date:** [February 26, 2015, 7:53am UTC](https://forum.sierrawireless.com/t/posting-with-content-length/7779/1 "2015-02-26T07:53:05Z")

</div>

Hi

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:

```auto
_sessionChannel = wip_HTTPClientCreateOpts (NULL, NULL,
	//WIP_COPT_HTTP_DATA_ENCOD, 0,
	//WIP_COPT_HTTP_VERSION, wip_httpVersion_e::WIP_HTTP_VERSION_1_0,
	WIP_COPT_HTTP_HEADER, "User-Agent", "WIP-HTTP-Client/1.0",
	WIP_COPT_END);
```

Data channel like this:

```auto
_dataChannel = wip_getFileOpts (_sessionChannel, const_cast<ascii*> (_url.c_str ()),
	 HttpClient::HttpClientImpl::HttpEventHandler, this,
	 WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_POST,
	 //WIP_COPT_HTTP_DATA_ENCOD, 0,
	 //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(),
	 WIP_COPT_END);
```

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?

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.sierrawireless.com/u/davidc)\
**Post date:** [March 1, 2015, 9:49am UTC](https://forum.sierrawireless.com/t/posting-with-content-length/7779/2 "2015-03-01T09:49:05Z")

</div>

Hiya,

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

---

<div class="post-metadata">

**Author:** ![aliceta](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@aliceta](https://forum.sierrawireless.com/u/aliceta)\
**Post date:** [December 21, 2017, 2:14am UTC](https://forum.sierrawireless.com/t/posting-with-content-length/7779/3 "2017-12-21T02:14:40Z")

</div>

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