Hi,
I am using ESP32
I am looking for sample example for sending the data using POST method over HTTPS without certificate.
How can I send post request without specifying the certificate?
Is there a way to mark the connection insecure?
Appreciate any pointers/sample regarding the issue.
Thanks
/Hp
ESP32: POST request over https without certificate
-
- Posts: 16
- Joined: Wed Jun 26, 2019 7:11 am
Re: ESP32: POST request over https without certificate
Is the ESP32 the sending part (or, the client)? In that case there's no need for a certifcate, because a certificate is only to be sure that the client is connected to the right server (and not a mitm). So, the certifcate is recommended but not needed for the https connection itself.
-
- Posts: 16
- Joined: Wed Jun 26, 2019 7:11 am
Re: ESP32: POST request over https without certificate
Hello,
Yes, ESP is sending part. It sends data to server.
I am referring "https_async" from https://github.com/espressif/esp-idf/bl ... _example.c
The example works fine with the test url in method but if I change the url to my server url with custom post data, it fails with following error,
The modified code for https_async is as below
The same url works fine with Postman and I could get the response.
Appreciate any pointers on this issues.
Thanks
/Hp
Yes, ESP is sending part. It sends data to server.
I am referring "https_async" from https://github.com/espressif/esp-idf/bl ... _example.c
The example works fine with the test url in method but if I change the url to my server url with custom post data, it fails with following error,
Code: Select all
I (6203) HTTP_CLIENT: Connected to AP, begin http example
E (9033) TRANS_SSL: esp_tls_conn_read error, errno=No more processes
E (9333) esp-tls: read error :-80:
E (9333) TRANS_SSL: esp_tls_conn_read error, errno=Connection reset by peer
E (9343) HTTP_CLIENT: Error perform http request ESP_ERR_HTTP_FETCH_HEADER
I (9343) HTTP_CLIENT: Finish http example
Code: Select all
static void https_async(void)
{
esp_http_client_config_t config = {
//.url = "https://postman-echo.com/post",
.url = "https://my-server-url.com/api/Test/TestCall/",
.event_handler = _http_event_handler,
.is_async = true,
.timeout_ms = 5000,
};
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_err_t err;
const char *post_data = "DATA=105";
esp_http_client_set_method(client, HTTP_METHOD_POST);
esp_http_client_set_post_field(client, post_data, strlen(post_data));
while (1) {
err = esp_http_client_perform(client);
if (err != ESP_ERR_HTTP_EAGAIN) {
break;
}
}
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
}
esp_http_client_cleanup(client);
}
Appreciate any pointers on this issues.
Thanks
/Hp
Re: ESP32: POST request over https without certificate
In the example the certificate isn't set either, so that proves it's not necessary.
Is the server returning anything? You may try to set .is_async = false;
Or, to test the connection to your own server, try this https example: https://docs.espressif.com/projects/esp ... html#https
Change the .url and remove the .cert_pem
Is the server returning anything? You may try to set .is_async = false;
Or, to test the connection to your own server, try this https example: https://docs.espressif.com/projects/esp ... html#https
Change the .url and remove the .cert_pem
-
- Posts: 16
- Joined: Wed Jun 26, 2019 7:11 am
Re: ESP32: POST request over https without certificate
Tried with the suggest example, still facing the same issue....
Could this be because of TLS version? How can I see the TLS version and change it?
Code: Select all
static void https_rest()
{
esp_http_client_config_t config = {
.url = "https://my-server-url.com/api/Test/TestCall/",
.event_handler = _http_event_handler,
//.cert_pem = howsmyssl_com_root_cert_pem_start,
};
esp_http_client_handle_t client = esp_http_client_init(&config);
{
// POST
const char *post_data = "DATA=1100";
esp_http_client_set_url(client, "https://my-server-url.com/api/Test/TestCall/");
esp_http_client_set_method(client, HTTP_METHOD_POST);
esp_http_client_set_post_field(client, post_data, strlen(post_data));
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %d\n",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP POST request failed: %s", esp_err_to_name(err));
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
esp_http_client_cleanup(client);
}
Re: ESP32: POST request over https without certificate
Hmm, runnin' out of options here..
I do know that a certificate is not needed (run https without it myself), as you can test with another website.
You also can connect to another site, so your ESP and IDF must be ok (imho).
One last suggestion: (assuming you run php on the webserver): what happens when you add the full path of the url?
So: https://my-server-url.com/api/Test/TestCall/post.php (correct name of course)
I do know that a certificate is not needed (run https without it myself), as you can test with another website.
You also can connect to another site, so your ESP and IDF must be ok (imho).
One last suggestion: (assuming you run php on the webserver): what happens when you add the full path of the url?
So: https://my-server-url.com/api/Test/TestCall/post.php (correct name of course)
Who is online
Users browsing this forum: No registered users and 419 guests