esp8266 / esp8266/Arduino

Core 3.1.1 - ESP8266HTTPClient.h getString() empty or truncated - read Timeout

Open
#8,871 29 comments 0 reactions 0 assignees View on GitHub
component: web type: troubleshooting
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

### Basic Infos

- [X ] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [ X] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [ X] I have tested that the issue is present in current master branch (aka latest git).
- [X ] I have searched the issue tracker for a similar issue.
- [X] If there is a stack dump, I have decoded it.
- [X ] I have filled out all fields below.

#### Platform

- Hardware: [ESP01|
- Core Version: [3.1.1]
- Development Env: [Arduino IDE]
- Operating System: [Windows]

### Settings in IDE

- Module: [Generic ESP8266 Module]
- Flash Mode: [qio]
- Flash Size: [1MB]
- lwip Variant: [v2 Higher Bandwidth]
- Reset Method: [nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [160MHz]
- Upload Using: [SERIAL]
- Upload Speed: [460800] (serial upload only)

### Problem Description
When I make https.GET not the all data received gets read into payload.

ESP8266Http library returms read Timeout
- [HTTP-Client][returnError] error(-11): read Timeout

https.setTimeout(10000); does not help

Sending same query in web browser, reply is received within 2 seconds always.

Full XML response is around 3700 bytes, but only part of it is in payload (ie. some 1200 bytes but it varies from 0...3700)
despite that HTTP_CODE is 200 and [HTTP-Client] read chunk len is 3701

**CODE:**
```
WiFiClientSecure *client = new WiFiClientSecure;
int httpCode;
if (client) {
client->setInsecure();

Serial.println(String(F("[ENTS]: Today url:")) + String(url));
if (https.begin(*client, url)) {
https.addHeader("Content-Type", "application/xml");
https.setTimeout(10000);
httpCode = https.GET();
Serial.println(String(F("[ENTS]: HTTP_CODE: ")) + String(httpCode));
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.println(String(F("[ENTS]: Length="))+String(payload.length()));
Serial.println(payload);
```

**### Debug printed with myown and HTTP_CLIENT DEBUG**
----------------------------------------------------------------------
```
[ENTS]: Today url:https://web-api.tp.entsoe.eu/api?securityToken=XXXXXXXXXXXXXX&documentType=A44&in_Domain=10Y1001A1001A46L&out_Domain=10Y1001A1001A46L&periodStart=202302262300&periodEnd=202302272300

[HTTP-Client][begin] url: https://web-api.tp.entsoe.eu/api?securityToken=XXXXXXXXXXXXXX&documentType=A44&in_Domain=10Y1001A1001A46L&out_Domain=10Y1001A1001A46L&periodStart=202302262300&periodEnd=202302272300

[HTTP-Client][begin] host: web-api.tp.entsoe.eu port: 443 url: /api?securityToken=XXXXXXXXXXXXXX&documentType=A44&in_Domain=10Y1001A1001A46L&out_Domain=10Y1001A1001A46L&periodStart=202302262300&periodEnd=202302272300

[HTTP-Client][sendRequest] type: 'GET' redirCount: 0
[HTTP-Client] connected to web-api.tp.entsoe.eu:443
[HTTP-Client] sending request header
-----
GET /api?securityToken=XXXXXXXXXXXXXX&documentType=A44&in_Domain=10Y1001A1001A46L&out_Domain=10Y1001A1001A46L&periodStart=202302262300&periodEnd=202302272300 HTTP/1.1
Host: web-api.tp.entsoe.eu
User-Agent: ESP8266HTTPClient
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0
Connection: keep-alive
Content-Type: application/xml
Content-Length: 0

-----
[HTTP-Client][handleHeaderResponse] RX: 'HTTP/1.1 200 OK
'
[HTTP-Client][handleHeaderResponse] RX: 'Date: Mon, 27 Feb 2023 17:17:21 GMT
'
[HTTP-Client][handleHeaderResponse] RX: 'Server: Apache
'
[HTTP-Client][handleHeaderResponse] RX: 'Strict-Transport-Security: max-age=31536000 ; includeSubDomains
'
[HTTP-Client][handleHeaderResponse] RX: 'X-Powered-By: Undertow/1
'
[HTTP-Client][handleHeaderResponse] RX: 'Keep-Alive: timeout=5, max=100
'
[HTTP-Client][handleHeaderResponse] RX: 'Connection: Keep-Alive
'
[HTTP-Client][handleHeaderResponse] RX: 'Transfer-Encoding: chunked
'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Type: text/xml
'
[HTTP-Client][handleHeaderResponse] RX: '
'
[HTTP-Client][handleHeaderResponse] code: 200
[HTTP-Client][handleHeaderResponse] Transfer-Encoding: chunked
[ENTS]: HTTP_CODE: 200
[HTTP-Client] read chunk len: 3701
[HTTP-Client][returnError] error(-11): read Timeout
[HTTP-Client][returnError] tcp stop
[ENTS]: Length=1260

d2145fefc7324f33a62e9ce82a4f3a17
1
A44
10X1001A1001A450
A32
10X1001A1001A450
A33
2023-02-27T17:17:22Z

2023-02-26T23:00Z
2023-02-27T23:00Z


1
A62
10Y1001A1001A46L
10Y1001A1001A46L
EUR
MWH
A01


2023-02-26T23:00Z
2023-02-27T23:00Z


```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.