[GH-ISSUE #1235] ERROR:The Content-Length header occurred more than once, at most one is allowed. #1054

Closed
opened 2026-02-28 01:28:19 +03:00 by kerem · 19 comments
Owner

Originally created by @EgHubs on GitHub (Mar 30, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1235

Hardware

WiFimanager Branch/Release: Master

Esp8266

Hardware: ESP-12e

Core Version: 2.7.4

Description

I don't know if this is supposed to be posted here but when I try to make an HTTP request for the esp from my mobile application that I am developing while it's on AP mode and waiting for configuration i.e, http://192.168.4.1
I get the following error
The Content-Length header occurred more than once, at most one is allowed.
though I can communicate it with google chrome as normal.
keep in mind that when I try to communicate to the esp after its configuration like http://192.168.1.200 it's all good with the same code from my flutter application.
I don't know what happens in there, I was hoping for any help by your side
I'm using the latest library release 0.16
I am developing a flutter application and making an HTTP request with the HTTP package

Module: NodeMcu

Originally created by @EgHubs on GitHub (Mar 30, 2021). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1235 #### Hardware WiFimanager Branch/Release: Master Esp8266 Hardware: ESP-12e Core Version: 2.7.4 ### Description I don't know if this is supposed to be posted here but when I try to make an HTTP request for the esp from my mobile application that I am developing while it's on AP mode and waiting for configuration i.e, `http://192.168.4.1 ` I get the following error `The Content-Length header occurred more than once, at most one is allowed. ` though I can communicate it with google chrome as normal. keep in mind that when I try to communicate to the esp after its configuration like `http://192.168.1.200 ` it's all good with the same code from my flutter application. I don't know what happens in there, I was hoping for any help by your side I'm using the latest library release `0.16` I am developing a flutter application and making an HTTP request with the HTTP [package](https://pub.dev/packages/http) Module: NodeMcu
kerem 2026-02-28 01:28:19 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@EgHubs commented on GitHub (Mar 30, 2021):

What made me post it here is someone's comment on StackOverflow, he told me that

It sounds like your HTTP server is incorrectly sending the Content-Length header in the HTTP response.

<!-- gh-comment-id:810592447 --> @EgHubs commented on GitHub (Mar 30, 2021): What made me post it here is someone's comment on StackOverflow, he told me that > It sounds like your HTTP server is incorrectly sending the Content-Length header in the HTTP response.
Author
Owner

@tablatronix commented on GitHub (Mar 31, 2021):

I will take a look can you try with master? Also provide serial log and which page are you requesting?

<!-- gh-comment-id:810688137 --> @tablatronix commented on GitHub (Mar 31, 2021): I will take a look can you try with master? Also provide serial log and which page are you requesting?
Author
Owner

@EgHubs commented on GitHub (Mar 31, 2021):

I am requesting the configuration page with the following link:
http://192.168.4.1/wifisave?s=myWifi&p=myPass&ip=192.168.1.203&gw=192.168.1.1&sn=255.255.255.0&email=new@test.com&pass=123456789&alarm=0

and this is the log with the master branch (note: I am blocking the MCU from joining my router for testing):

reading config file
opened config file
{"ip":"192.168.1.203","gateway":"192.168.1.1","subnet":"255.255.255.0","api_token":"123456789&alarm=1","mqtt_port":"new@test.com","mqtt_server":"1"}
parsed json
setting custom ip from config
192.168.1.203
 mqtt_port IS
new@test.com
API TOKEN IS
123456789&alarm=1
AlarmSettings are
1
IAM HEREEE2222
*wm:[2] Added Parameter: alarm
*wm:[2] Added Parameter: email
*wm:[2] Added Parameter: pass
IAM HEREEE3333
Current SSID
Shalaby
connectingggggg)
shouldSaveConfig Is
0
*wm:[1] AutoConnect 
*wm:[2] Connecting as wifi client... 
*wm:[2] setSTAConfig static ip not set, skipping 
*wm:[1] Connecting to SAVED AP: Shalaby
*wm:[1] connectTimeout not set, ESP waitForConnectResult... 
*wm:[2] Connection result: WL_CONNECT_FAILED
*wm:[1] AutoConnect: FAILED 
*wm:[2] Starting Config Portal 
*wm:[2] AccessPoint set password is VALID 
*wm:[2] Disabling STA 
*wm:[2] Enabling AP 
*wm:[1] StartAP with SSID:  M2
*wm:[1] AP IP address: 192.168.4.1
*wm:[1] Starting Web Portal 
*wm:[2] HTTP server started 
*wm:[2] Config Portal Running, blocking, waiting for clients... 
*wm:[2] NUM CLIENTS:  1
*wm:[2] <- HTTP Root 
*wm:[2] <- Request redirected to captive portal 
*wm:[2] <- HTTP WiFi save  
*wm:[2] Parameters 
*wm:[2] -------------------- 
*wm:[2] alarm: 0
*wm:[2] email: new@test.com
*wm:[2] pass: 123456789
*wm:[2] -------------------- 
*wm:[2] processing save 
*wm:[2] Connecting as wifi client... 
*wm:[2] Custom static IP/GW/Subnet/DNS 
*wm:[2] Custom STA IP/GW/Subnet 
*wm:[1] STA IP set: 192.168.1.203
*wm:[1] CONNECTED:
*wm:[1] Connecting to NEW AP: Shalaby
*wm:[1] connectTimeout not set, ESP waitForConnectResult... 
*wm:[2] Connection result: WL_CONNECT_FAILED
*wm:[0] [ERROR] Connect to new AP Failed 
*wm:[2] WiFi/Param save callback 
Should save config heree in callback
*wm:[2] <- HTTP WiFi save  
*wm:[2] Parameters 
*wm:[2] -------------------- 
*wm:[2] alarm: 0
*wm:[2] email: new@test.com
*wm:[2] pass: 123456789
*wm:[2] -------------------- 
*wm:[2] disconnect configportal 
*wm:[2] restoring usermode STA
*wm:[2] wifi status: WL_CONNECT_FAILED
*wm:[2] wifi mode: STA
*wm:[1] config portal exiting 
failed to connect and hit timeout

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3584, room 16 
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld
mounted file system
reading config file
opened config file
{"ip":"192.168.1.203","gateway":"192.168.1.1","subnet":"255.255.255.0","api_token":"123456789&alarm=1","mqtt_port":"new@test.com","mqtt_server":"1"}
parsed json
setting custom ip from config
192.168.1.203
 mqtt_port IS
new@test.com
API TOKEN IS
123456789&alarm=1
AlarmSettings are
1
IAM HEREEE2222
*wm:[2] Added Parameter: alarm
*wm:[2] Added Parameter: email
*wm:[2] Added Parameter: pass
IAM HEREEE3333
Current SSID
Shalaby
connectingggggg)
shouldSaveConfig Is
0
*wm:[1] AutoConnect 
*wm:[2] Connecting as wifi client... 
*wm:[2] setSTAConfig static ip not set, skipping 
*wm:[1] Connecting to SAVED AP: Shalaby
*wm:[1] connectTimeout not set, ESP waitForConnectResult... 
*wm:[2] Connection result: WL_CONNECT_FAILED
*wm:[1] AutoConnect: FAILED 
*wm:[2] Starting Config Portal 
*wm:[2] AccessPoint set password is VALID 
*wm:[2] Disabling STA 
*wm:[2] Enabling AP 
*wm:[1] StartAP with SSID:  M2
*wm:[1] AP IP address: 192.168.4.1
*wm:[1] Starting Web Portal 
*wm:[2] HTTP server started 
*wm:[2] Config Portal Running, blocking, waiting for clients... 
*wm:[2] NUM CLIENTS:  0

it seems that the esp receives the HTTP request but it doesn't respond back or it responds back the Content-Length header incorrectly or something like that.

<!-- gh-comment-id:810700966 --> @EgHubs commented on GitHub (Mar 31, 2021): I am requesting the configuration page with the following link: `http://192.168.4.1/wifisave?s=myWifi&p=myPass&ip=192.168.1.203&gw=192.168.1.1&sn=255.255.255.0&email=new@test.com&pass=123456789&alarm=0` and this is the log with the master branch (note: I am blocking the MCU from joining my router for testing): ``` reading config file opened config file {"ip":"192.168.1.203","gateway":"192.168.1.1","subnet":"255.255.255.0","api_token":"123456789&alarm=1","mqtt_port":"new@test.com","mqtt_server":"1"} parsed json setting custom ip from config 192.168.1.203 mqtt_port IS new@test.com API TOKEN IS 123456789&alarm=1 AlarmSettings are 1 IAM HEREEE2222 *wm:[2] Added Parameter: alarm *wm:[2] Added Parameter: email *wm:[2] Added Parameter: pass IAM HEREEE3333 Current SSID Shalaby connectingggggg) shouldSaveConfig Is 0 *wm:[1] AutoConnect *wm:[2] Connecting as wifi client... *wm:[2] setSTAConfig static ip not set, skipping *wm:[1] Connecting to SAVED AP: Shalaby *wm:[1] connectTimeout not set, ESP waitForConnectResult... *wm:[2] Connection result: WL_CONNECT_FAILED *wm:[1] AutoConnect: FAILED *wm:[2] Starting Config Portal *wm:[2] AccessPoint set password is VALID *wm:[2] Disabling STA *wm:[2] Enabling AP *wm:[1] StartAP with SSID: M2 *wm:[1] AP IP address: 192.168.4.1 *wm:[1] Starting Web Portal *wm:[2] HTTP server started *wm:[2] Config Portal Running, blocking, waiting for clients... *wm:[2] NUM CLIENTS: 1 *wm:[2] <- HTTP Root *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP WiFi save *wm:[2] Parameters *wm:[2] -------------------- *wm:[2] alarm: 0 *wm:[2] email: new@test.com *wm:[2] pass: 123456789 *wm:[2] -------------------- *wm:[2] processing save *wm:[2] Connecting as wifi client... *wm:[2] Custom static IP/GW/Subnet/DNS *wm:[2] Custom STA IP/GW/Subnet *wm:[1] STA IP set: 192.168.1.203 *wm:[1] CONNECTED: *wm:[1] Connecting to NEW AP: Shalaby *wm:[1] connectTimeout not set, ESP waitForConnectResult... *wm:[2] Connection result: WL_CONNECT_FAILED *wm:[0] [ERROR] Connect to new AP Failed *wm:[2] WiFi/Param save callback Should save config heree in callback *wm:[2] <- HTTP WiFi save *wm:[2] Parameters *wm:[2] -------------------- *wm:[2] alarm: 0 *wm:[2] email: new@test.com *wm:[2] pass: 123456789 *wm:[2] -------------------- *wm:[2] disconnect configportal *wm:[2] restoring usermode STA *wm:[2] wifi status: WL_CONNECT_FAILED *wm:[2] wifi mode: STA *wm:[1] config portal exiting failed to connect and hit timeout ets Jan 8 2013,rst cause:2, boot mode:(3,6) load 0x4010f000, len 3584, room 16 tail 0 chksum 0xb0 csum 0xb0 v2843a5ac ~ld mounted file system reading config file opened config file {"ip":"192.168.1.203","gateway":"192.168.1.1","subnet":"255.255.255.0","api_token":"123456789&alarm=1","mqtt_port":"new@test.com","mqtt_server":"1"} parsed json setting custom ip from config 192.168.1.203 mqtt_port IS new@test.com API TOKEN IS 123456789&alarm=1 AlarmSettings are 1 IAM HEREEE2222 *wm:[2] Added Parameter: alarm *wm:[2] Added Parameter: email *wm:[2] Added Parameter: pass IAM HEREEE3333 Current SSID Shalaby connectingggggg) shouldSaveConfig Is 0 *wm:[1] AutoConnect *wm:[2] Connecting as wifi client... *wm:[2] setSTAConfig static ip not set, skipping *wm:[1] Connecting to SAVED AP: Shalaby *wm:[1] connectTimeout not set, ESP waitForConnectResult... *wm:[2] Connection result: WL_CONNECT_FAILED *wm:[1] AutoConnect: FAILED *wm:[2] Starting Config Portal *wm:[2] AccessPoint set password is VALID *wm:[2] Disabling STA *wm:[2] Enabling AP *wm:[1] StartAP with SSID: M2 *wm:[1] AP IP address: 192.168.4.1 *wm:[1] Starting Web Portal *wm:[2] HTTP server started *wm:[2] Config Portal Running, blocking, waiting for clients... *wm:[2] NUM CLIENTS: 0 ``` it seems that the esp receives the HTTP request but it doesn't respond back or it responds back the Content-Length header incorrectly or something like that.
Author
Owner

@tablatronix commented on GitHub (Mar 31, 2021):

Add it is only that page?
Does it do the same if not sending params as get arguments?

<!-- gh-comment-id:810743370 --> @tablatronix commented on GitHub (Mar 31, 2021): Add it is only that page? Does it do the same if not sending params as get arguments?
Author
Owner

@EgHubs commented on GitHub (Mar 31, 2021):

Yes i get that error only in that page, i.e, when i try to make an http request to the esp after configuration with a link like 192.168.1.203/ it's all good and okay and no error is catched

<!-- gh-comment-id:810883413 --> @EgHubs commented on GitHub (Mar 31, 2021): Yes i get that error only in that page, i.e, when i try to make an http request to the esp after configuration with a link like `192.168.1.203/` it's all good and okay and no error is catched
Author
Owner

@EgHubs commented on GitHub (Apr 4, 2021):

Sorry but I am still stuck in this error, any news? :)

<!-- gh-comment-id:813102271 --> @EgHubs commented on GitHub (Apr 4, 2021): Sorry but I am still stuck in this error, any news? :)
Author
Owner

@tablatronix commented on GitHub (Apr 4, 2021):

Sorry I have not had a chance to look at it.

<!-- gh-comment-id:813108906 --> @tablatronix commented on GitHub (Apr 4, 2021): Sorry I have not had a chance to look at it.
Author
Owner

@EgHubs commented on GitHub (Apr 4, 2021):

No problem at all for sure, hope you have soon 😄

<!-- gh-comment-id:813117265 --> @EgHubs commented on GitHub (Apr 4, 2021): No problem at all for sure, hope you have soon 😄
Author
Owner

@EgHubs commented on GitHub (Apr 13, 2021):

Here again, still no progress on this error.
when I tried to get the response from an API tester this is what I get

> Host: 192.168.4.1
> User-Agent: insomnia/2021.2.2
> Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> Accept: */*
> Content-Length: 25

| --X-INSOMNIA-BOUNDARY--

* We are completely uploaded and fine
* Mark bundle as not supporting multiuse

< HTTP/1.1 200 OK
< Content-Type: text/html
< Content-Length: 1210
< Content-Length: 1210 //second one.
< Connection: close

see I get Content-Length twice here, the server sends the Content-Length twice which is the error title that appears for me. i tried more than one site and I only get the Content-Length once
for example

> GET / HTTP/1.1
> Host: github.com
> User-Agent: insomnia/2021.2.2
> Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> Accept: */*
> Content-Length: 25

| --X-INSOMNIA-BOUNDARY--

* We are completely uploaded and fine
* Mark bundle as not supporting multiuse

< HTTP/1.1 301 Moved Permanently
< Content-Length: 0
< Location: https://github.com/
< connection: close

keep in mind that the server receives the request but it responds back incorrectly.
I really hope that this makes it easier to solve the problem.

<!-- gh-comment-id:818916972 --> @EgHubs commented on GitHub (Apr 13, 2021): Here again, still no progress on this error. when I tried to get the response from an API tester this is what I get ``` > Host: 192.168.4.1 > User-Agent: insomnia/2021.2.2 > Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY > Accept: */* > Content-Length: 25 | --X-INSOMNIA-BOUNDARY-- * We are completely uploaded and fine * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Content-Type: text/html < Content-Length: 1210 < Content-Length: 1210 //second one. < Connection: close ``` see I get Content-Length twice here, the server sends the Content-Length twice which is the error title that appears for me. i tried more than one site and I only get the Content-Length once for example ``` > GET / HTTP/1.1 > Host: github.com > User-Agent: insomnia/2021.2.2 > Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY > Accept: */* > Content-Length: 25 | --X-INSOMNIA-BOUNDARY-- * We are completely uploaded and fine * Mark bundle as not supporting multiuse < HTTP/1.1 301 Moved Permanently < Content-Length: 0 < Location: https://github.com/ < connection: close ``` keep in mind that the server receives the request but it responds back incorrectly. I really hope that this makes it easier to solve the problem.
Author
Owner

@tablatronix commented on GitHub (Apr 13, 2021):

crap I will look right now

<!-- gh-comment-id:818966019 --> @tablatronix commented on GitHub (Apr 13, 2021): crap I will look right now
Author
Owner

@tablatronix commented on GitHub (Apr 13, 2021):

I can only assume that the webserver lib is sending this automatically.. I do not see anything in WM that would send this more than once, I will look into it further.

Can try the params page save, maybe for forms it auto sends it?

<!-- gh-comment-id:818968461 --> @tablatronix commented on GitHub (Apr 13, 2021): I can only assume that the webserver lib is sending this automatically.. I do not see anything in WM that would send this more than once, I will look into it further. Can try the params page save, maybe for forms it auto sends it?
Author
Owner

@tablatronix commented on GitHub (Apr 13, 2021):

// handlewifisave
  server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); // content length
  server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL)); // cors
  server->send(200, FPSTR(HTTP_HEAD_CT), page);

I wonder if its the CORS on that page?
Maybe remove those and see what happens

<!-- gh-comment-id:818969917 --> @tablatronix commented on GitHub (Apr 13, 2021): ```C++ // handlewifisave server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); // content length server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL)); // cors server->send(200, FPSTR(HTTP_HEAD_CT), page); ``` I wonder if its the CORS on that page? Maybe remove those and see what happens
Author
Owner

@tablatronix commented on GitHub (Apr 13, 2021):

Yup its definitely sending it twice

<!-- gh-comment-id:818973983 --> @tablatronix commented on GitHub (Apr 13, 2021): Yup its definitely sending it twice
Author
Owner

@tablatronix commented on GitHub (Apr 13, 2021):

It seems content-length was added in 2015 maybe it was broken , no idea why this has never been noticed, I can remove them and test on older esp versions and see if it still works.

<!-- gh-comment-id:818978527 --> @tablatronix commented on GitHub (Apr 13, 2021): It seems content-length was added in 2015 maybe it was broken , no idea why this has never been noticed, I can remove them and test on older esp versions and see if it still works.
Author
Owner

@tablatronix commented on GitHub (Apr 13, 2021):

It also seems to support httpclient requests now like the async lib, so that can also be changed, as add header already does dup checking

<!-- gh-comment-id:818979364 --> @tablatronix commented on GitHub (Apr 13, 2021): It also seems to support httpclient requests now like the async lib, so that can also be changed, as add header already does dup checking
Author
Owner

@tablatronix commented on GitHub (Apr 13, 2021):

Try it now, I tried old versions and its fine, so I am just gonna leave these out now

<!-- gh-comment-id:819004070 --> @tablatronix commented on GitHub (Apr 13, 2021): Try it now, I tried old versions and its fine, so I am just gonna leave these out now
Author
Owner

@EgHubs commented on GitHub (Apr 13, 2021):

Woooh !!, nice now it's working perfectly :), I am so happy that I did help to contribute to something important like that in this great library, I also have no idea why this error appeared to me, maybe some updates on the Flutter side refused this error.
I would suggest a quick fix update with a new version like 0.16.1 or something.
again thank you for helping me and thank you again for being such an active person in this library community and helping people.

<!-- gh-comment-id:819016469 --> @EgHubs commented on GitHub (Apr 13, 2021): Woooh !!, nice now it's working perfectly :), I am so happy that I did help to contribute to something important like that in this great library, I also have no idea why this error appeared to me, maybe some updates on the Flutter side refused this error. I would suggest a quick fix update with a new version like 0.16.1 or something. again thank you for helping me and thank you again for being such an active person in this library community and helping people.
Author
Owner

@tablatronix commented on GitHub (Apr 13, 2021):

I would assume httpdclients should just ignore dup headers if they are identical, but who knows, technically it is against spec to send multiples

<!-- gh-comment-id:819032342 --> @tablatronix commented on GitHub (Apr 13, 2021): I would assume httpdclients should just ignore dup headers if they are identical, but who knows, technically it is against spec to send multiples
Author
Owner

@EgHubs commented on GitHub (Apr 13, 2021):

I would assume httpdclients should just ignore dup headers if they are identical, but who knows, technically it is against spec to send multiples

Wil, based on the question I submitted on StackOverFlow someone submitted an issue requesting to ignore the error if the values are identical. like you are recommending.

<!-- gh-comment-id:819049050 --> @EgHubs commented on GitHub (Apr 13, 2021): > I would assume httpdclients should just ignore dup headers if they are identical, but who knows, technically it is against spec to send multiples Wil, based on the [question](https://stackoverflow.com/q/66771165/13444299) I submitted on StackOverFlow someone submitted an [issue](https://github.com/dart-lang/sdk/issues/45679) requesting to ignore the error if the values are identical. like you are recommending.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1054
No description provided.