Https request / Content-length = 0

Sergi_SP
Posts: 2
Joined: Mon Sep 27, 2021 2:48 pm

Https request / Content-length = 0

Postby Sergi_SP » Tue Sep 28, 2021 6:35 am

Hi,

I have been able to get data from and API endpoint using esp_http_client_open() or esp_http_client_perform().

But now I can't because the server where I request for getting data has activate certificate authorization for some services. I always get content-length = 0.

However the endpoint I call is not protected usign certificate authorization. But if you call the endpoint usign a web browser you must skip a window popup requesting for a certificate. After skipping this popup you get the data because authorization is not required indeed.

Moreover if you use Curl command to call this endpoint you get the data without problems.

I've have seen a few examples using a port of curl command for esp32 devices but I haven't been able to make it working.

Are there other functions instead of esp_http_client_open() or esp_http_client_perform() I can try?

Including a certificate in my request is not an option because I have to mantaing compatibility with other devices that use certificates.

Please, may you help me?

Thanks in advance

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: Https request / Content-length = 0

Postby chegewara » Tue Sep 28, 2021 7:33 pm

Its very old code, i believe its from before esp-idf v3, but you could try it:
https://github.com/nkolban/esp32-snippe ... aster/curl

I didnt use it myself.

jdoubleu
Posts: 8
Joined: Wed Sep 29, 2021 3:58 pm

Re: Https request / Content-length = 0

Postby jdoubleu » Wed Sep 29, 2021 4:10 pm

What status code do you get back from the API on the first call? Is it a "401 Unauthorized"?

I assume curl automatically re-tries your request if you didn't provide any information about client certificate authentication, like your web browser, which prompted you first.

I found this function in the documentation, but I'm not sure what it does or how it works. Especially when you want to provide a client certificate. But maybe you can try it out: https://docs.espressif.com/projects/esp ... t_handle_t
Especially

Sergi_SP
Posts: 2
Joined: Mon Sep 27, 2021 2:48 pm

Re: Https request / Content-length = 0

Postby Sergi_SP » Fri Oct 15, 2021 9:51 am

Hi,

Finally the server admin excluded endpoints from certificate authorization.

Now it works as expected.

Thanks for your reply guys

Best regards

Who is online

Users browsing this forum: Majestic-12 [Bot], MicroController and 110 guests