I try to fetch a binary file from an Azure Blob Storage, using esp_http_client, IDF v5.0.1. The fetch works in Postman or in a browser, which means the url path and the SAS token are correct.
The connection to the Azure server is established, but I get the error message: "Server failed to authenticate the request":
Code: Untitled.txt Select all
I(15113) APP : Opened successfully the HTTP connection
I(15273) HTTP_CLIENT : Body received in fetch header state, 0x3ffbb6da, 166
I(15293) APP : Read data : ���< ? xml version = "1.0" encoding = "utf-8" ? >
<Error><Code>AuthenticationFailed< / Code><Message>Server failed to authenticate the request.Make sure the value of Authorization header is formed correctly including the signature.
RequestId : 01100f54 - 901e-0045 - 18cc - e3e32c000000I have tried various combinations for the connection setting: the url with and without the SAS at the end, and setting the SAS in the http header "Authorization" field.
I suspect the problem comes from the way the connection data is set / arranged in the esp http client. This is the code that I have tested:
Code: Untitled.c Select all
esp_http_client_config_t config = {
//.url = "https://name.blob.core.windows.net/test/v0.0.2-fw.bin&sp=r&...0MtMgNI%3D",
.url = "https://name.blob.core.windows.net/test/v0.0.2-fw.bin",
.transport_type = HTTP_TRANSPORT_OVER_SSL,
.event_handler = http_event_handler,
.cert_pem = rootCaPem,
.cert_len = rootCaPemLen,
.timeout_ms = RECEIVE_TIMEOUT,
.keep_alive_enable = true,
.skip_cert_common_name_check = true,
//.use_global_ca_store = true
};
esp_http_client_handle_t client = esp_http_client_init(&config);
if (client == NULL) {
ESP_LOGE(TAG, "Failed to initialise HTTP connection");
return;
}
esp_http_client_set_header(client, "Authorization", "SharedAccessSignature sp=r&...0MtMgNI%3D");
//esp_http_client_set_header(client, "ContentType", "application/octet-stream");
esp_http_client_set_header(client, "Accept", "*/*"); // copied from Postman
esp_http_client_set_header(client, "Accept-Encoding", "gzip, deflate, br"); // copied from Postman
esp_http_client_set_header(client, "Host", "name.blob.core.windows.net");
esp_http_client_set_method(client, HTTP_METHOD_GET);
err = esp_http_client_open(client, 0);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
esp_http_client_cleanup(client);
return;
}
else {
ESP_LOGI(TAG, "Opened successfully the HTTP connection");
}
esp_http_client_fetch_headers(client);Any idea on why the Azure authorization fails?
Does anybody have an ESP http client example, for fetching data from an Azure Blob Storage?
I would really appreciate any help!
Thank you!
