Attempting to get the https_request_example working.
The example seemingly works fine as is with a GET. If I modify the GET to a POST, the write works, but the esp_tls_conn_read hangs for many seconds then eventually times out.
If I change the POST to an invalid request, the server returns the expected 500 error and immediately spits out all the html for the error as expected.
Much like this problem: viewtopic.php?f=13&t=7830#p32907
But changing out the HTTP/1.1 to HTTP/1.0 did not fix my problem.
static void https_get_request(esp_tls_cfg_t cfg)
{
char buf[512];
int ret, len;
size_t written_bytes = 0;
char *sendPacket = "{JSON PACKET HERE}";
char REQUEST[314] = "POST " WEB_URL " HTTP/1.1\r\n"
"Host: " WEB_SERVER ":443\r\n"
"User-Agent: esp-idf/1.0 esp32\r\n"
"Accept: text/html\r\n"
"Content-type: application/json\r\n"
"Content-length: 317\r\n\r\n";
strcat(REQUEST,sendPacket);
ESP_LOGI(TAG,"REQUEST=\n%s",REQUEST);
The rest of the example is un-modified.
This is the post text:
POST https://www.xxxxxxxx.com/data.asmx/Device HTTP/1.1
Host: www.xxxxxxxx.com:443
User-Agent: esp-idf/1.0 esp32
Accept: text/html
Content-type: application/json
Content-length: 314
{ JSON PACKET HERE }
Operation messages here. System hangs waiting for read return after len=511 until timeout.
I (5239) esp-x509-crt-bundle: Certificate validated
I (6959) WiFi: Connection established...
E (6969) WiFi: WRITE Ret=314
I (6969) WiFi: 314 bytes written
I (6969) WiFi: Reading HTTP response...
I (6969) WiFi: Len=511
E (131369) esp-tls-mbedtls: read error :-80:
I (131369) WiFi: tls_read_ret=-80
E (131369) WiFi: esp_tls_conn_read returned [-0x50](ERROR)
Clearly the read function is not returning the expected value and the server times out the connection, then the read do/while loop can continue and fails.
The code here is just test code.
What is it I am missing?
Thanks!
esp_tls_conn_read returns [-0x50](ERROR)
-
- Posts: 9
- Joined: Mon May 11, 2020 8:26 pm
Re: esp_tls_conn_read returns [-0x50](ERROR)
Sorry to bother everyone. The post content length is the length of the data you wish to send, not the length of the whole post string. In this case the webserver was waiting for 200+ bytes that wasn't being sent. So it just timed out and closed the connection.
Who is online
Users browsing this forum: Majestic-12 [Bot] and 115 guests