# Uclient-fetch: POST Content-length

**URL:** <https://forum.openwrt.org/t/uclient-fetch-post-content-length/26655>\
**Category:** Installing and Using OpenWrt\
**Created:** [December 7, 2018, 8:44am UTC](https://forum.openwrt.org/t/uclient-fetch-post-content-length/26655 "2018-12-07T08:44:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptlink](https://forum.openwrt.org/letter_avatar/ptlink/32/6_449c533f586939b6e5f246632a46421f.png) [@ptlink](https://forum.openwrt.org/u/ptlink)\
**Post date:** [December 7, 2018, 8:44am UTC](https://forum.openwrt.org/t/uclient-fetch-post-content-length/26655/1 "2018-12-07T08:44:43Z")

</div>

Running openwrt-18.06 branch (git-18.228.31946-f64b152)

When submitting a POST request using built-in wget command (which is actually uclient-fetch), the Content-Length is not present. Example:

`wget --post-data="a=b" http://httpbin.org/post -O -`

Server receive the following headers:

```
"headers": {
"Connection": "close",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "[httpbin.org](http://httpbin.org)",
"Transfer-Encoding": "chunked",
"User-Agent": "uclient-fetch"

```

Transfer-Encoding "chunked" used and there is no Content-length provided

Since the post data size is known during the request, is there a way to force Content-length header to appear?

Thanks

---

<div class="post-metadata">

**Author:** ![hamzakilic](https://forum.openwrt.org/letter_avatar/hamzakilic/32/6_449c533f586939b6e5f246632a46421f.png) [@hamzakilic](https://forum.openwrt.org/u/hamzakilic)\
**Post date:** [February 1, 2019, 1:17am UTC](https://forum.openwrt.org/t/uclient-fetch-post-content-length/26655/2 "2019-02-01T01:17:41Z")

</div>

you can't  
this is source code of uclient-fetch, also you cannot set Content-Type

```
static int init_request(struct uclient *cl)
320 {
321 int rc;
322 
323 out_offset = 0;
324 out_bytes = 0;
325 out_len = 0;
326 uclient_http_set_ssl_ctx(cl, ssl_ops, ssl_ctx, verify);
327 
328 if (timeout)
329 cl->timeout_msecs = timeout * 1000;
330 
331 rc = uclient_connect(cl);
332 if (rc)
333 return rc;
334 
335 msg_connecting(cl);
336 
337 rc = uclient_http_set_request_type(cl, post_data ? "POST" : "GET");
338 if (rc)
339 return rc;
340 
341 uclient_http_reset_headers(cl);
342 uclient_http_set_header(cl, "User-Agent", user_agent);
343 if (cur_resume)
344 check_resume_offset(cl);
345 
346 if (post_data) {
347 uclient_http_set_header(cl, "Content-Type", "application/x-www-form-urlencoded");
348 uclient_write(cl, post_data, strlen(post_data));
349 }
350 
351 rc = uclient_request(cl);
352 if (rc)
353 return rc;
354 
355 return 0;
356 }

```

---

<div class="post-metadata">

**Author:** ![stokito](https://forum.openwrt.org/user_avatar/forum.openwrt.org/stokito/32/7357_2.png) [@stokito](https://forum.openwrt.org/u/stokito)\
**Post date:** [May 9, 2022, 10:12pm UTC](https://forum.openwrt.org/t/uclient-fetch-post-content-length/26655/3 "2022-05-09T22:12:14Z")

</div>

Discussion when the code was added:  
[https://patchwork.ozlabs.org/project/lede/patch/CAHQM780agD+6-cCQmWuHzguHYVQiKiS-xAw+R7u=a\_PLvKP3Cg@mail.gmail.com/#1382522](https://patchwork.ozlabs.org/project/lede/patch/CAHQM780agD+6-cCQmWuHzguHYVQiKiS-xAw+R7u=a_PLvKP3Cg@mail.gmail.com/#1382522)

The uclient-fetch has inconvenient design in that place so it can send only with chunked encoding even while we already know the Content-Length.

But technically it's easy to add the CL header but I don't know if webservers can handle it correctly if CL is used with a chunked.

BusyBox httpd has a bug when sends the body with chunks as is into CGI script . So you can't use uclient-fetch with BB httpd. But uhttpd works correctly.
