Http request to an https site

kurtwerbrouck
Posts: 10
Joined: Tue Feb 16, 2021 2:37 pm

Http request to an https site

Postby kurtwerbrouck » Thu Jun 09, 2022 6:24 pm

Hello
In visual code i updated to frame work esp platform 4.4,
before this update i could do an http request to get the position of the ISS station.

void http_iss(void * pvParam)
{
esp_http_client_config_t config ;

config.url = ISS_SERVER.serverName;
config.transport_type = HTTP_TRANSPORT_OVER_TCP;
config.event_handler = _http_event_handler;
config.buffer_size = 2048;
esp_http_client_handle_t client = esp_http_client_init(&config);
ISS_SERVER.ISS_Json ="";

for(;;)
{
esp_http_client_set_header(client,"Content-Typ","application/json");
esp_http_client_set_header(client,"Connection" ,"Keep-Alive");
esp_http_client_set_header(client,"Keep-Alive" ,"timeout=5");

esp_err_t err = esp_http_client_perform(client);
Serial.printf("xxxxxxxxxxxxxxxxxx");
if (err == ESP_OK)
{
char *buffer = (char *) malloc(MAX_HTTP_RECV_BUFFER + 1); // http receive buffer
esp_http_client_read(client,buffer,esp_http_client_get_content_length(client)); //{"name":"iss","id":25544,"latitude":-16.048352510626,"longitude":-23.31397684452,"altitude":422.82941853046,"velocity":27564.33986479,"visibility":"daylight","footprint":4521.8303508566,"timestamp":1652553547,"daynum":2459714.2771644,"solar_lat":18.760279280377,"solar_lon":259.31318637856,"units":"kilometers"}

if ( esp_http_client_get_status_code(client) == 200)
{
char *dummy = (char *) malloc(esp_http_client_get_content_length(client)+1);
memcpy(dummy,buffer,esp_http_client_get_content_length(client));
dummy[esp_http_client_get_content_length(client)] = 0;
//Serial.printf("%d\n%s\n",esp_http_client_get_content_length(client),dummy);

ISS_SERVER.ISS_Json = "";

int content_lenght = 0;
content_lenght = esp_http_client_get_content_length(client);

for (int i=0;i<content_lenght;i++) {
ISS_SERVER.ISS_Json += buffer; //convert to string
}

DynamicJsonDocument ISS_json(512);
deserializeJson(ISS_json,ISS_SERVER.ISS_Json);

ISS_DATA.Altitude = ISS_json["altitude"];
ISS_DATA.lat = ISS_json["latitude"];
ISS_DATA.lon = ISS_json["longitude"];
ISS_DATA.Velocity = ISS_json["velocity"];
//ISS_DATA.Visibility = ISS_json["visibility"];

//Serial.printf("%.4f\t%.4f\t%.4f\t%.4f\n",ISS_DATA.Altitude,ISS_DATA.lat,ISS_DATA.lon,ISS_DATA.Velocity);
}
free(buffer);
}
err = esp_http_client_close(client);

assert(xQueueOverwrite(ISS_queue,&ISS_DATA));

Now after the update, i cant get it back on work
i have the next error:
E (148961) esp-tls-mbedtls: No server verification option set in esp_tls_cfg_t structure. Check esp_tls API reference
E (148961) esp-tls-mbedtls: Failed to set client configurations, returned [0x8017] (ESP_ERR_MBEDTLS_SSL_SETUP_FAILED)
E (148971) esp-tls: create_ssl_handle failed
E (148981) esp-tls: Failed to open new connection
E (148981) TRANSPORT_BASE: Failed to open a new connection
E (148991) HTTP_CLIENT: Connection failed, sock < 0

i found that i have to
You need certificate to make https requests. In case you dont want to implement this, just edit your sdkconfig "Allow potentially insecure options" -> true

"Skip server certificate verification by default" -> true


But i am on visual code, so i have to do this via the main.c file, any idea where and how to perform this action?

i just found this on the esp32 website

skip server verification: This is an insecure option provided in the ESP-TLS for testing purpose. The option can be set by enabling CONFIG_ESP_TLS_INSECURE and CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY in the ESP-TLS menuconfig. When this option is enabled the ESP-TLS will skip server verification by default when no other options for server verification are selected in the esp_tls_cfg_t structure.

Thanks

a2800276
Posts: 78
Joined: Sat Jan 23, 2016 1:59 pm

Re: Http request to an https site

Postby a2800276 » Thu Jun 09, 2022 8:21 pm

Could you apply some formatting to your post? It's nearly impossible to read the way it is.
Something seems off: the error message you are posting is complaining about improper tls use, but the code you posted doesn't (seem) to use tls anywhere. Something else is probably the matter. Make sure the firmware you think you are using is actually flashed to the device.

ESP_Sprite
Posts: 9772
Joined: Thu Nov 26, 2015 4:08 am

Re: Http request to an https site

Postby ESP_Sprite » Fri Jun 10, 2022 1:18 am

If you're using ESP-IDF and our extension for Visual Studio Code, you should be able to access menuconfig somewhere. I don't have that IDE installed, so I can't tell you where unfortunately, but it is in there.

Who is online

Users browsing this forum: No registered users and 12 guests