添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.
  • General issue report

    环境:esp32s3 + esp-idf 5.0
    问题:使用正确的证书情况下,使用 esp_http_client api 请求 www.timeapi.io 域名返回200 但获取长度为0。

    static void http_redirect_to_https(void) { esp_http_client_config_t config = { .url = "https://www.timeapi.io/api/TimeZone/ip?ipAddress=237.71.232.203", .event_handler = _http_event_handler, .cert_pem = howsmyssl_com_root_cert_pem_start, }; esp_http_client_handle_t client = esp_http_client_init(&config); esp_err_t err = esp_http_client_perform(client); if (err == ESP_OK) { ESP_LOGI(TAG, "HTTP redirect to HTTPS Status = %d, content_length = %lld", 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); }
    输出结果:
    (9899) HTTP_CLIENT: HTTP redirect to HTTPS Status = 200, content_length = -1 (9899) HTTP_CLIENT: HTTP_EVENT_DISCONNECTED

    正确情况:

    esp_http_client get 请求https 域名返回200 获取长度为0 esp_http_client get 请求https 域名返回200 获取长度为0 (IDFGH-9299) Feb 2, 2023

    @Wvirgil123 这个是 chunked 的数据,没有 content-length 字段,你工具上也显示的是 chunked 的。

    我打印 chunk_length 也是为0, 通过perform 方式可以获取到正确的 chunk 长度和数据吗?

    if (err == ESP_OK) {
    ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %lld",
    esp_http_client_get_status_code(client),
    esp_http_client_get_content_length(client));
    int len = 0;
    bool ret = esp_http_client_is_chunked_response(client);
    err = esp_http_client_get_chunk_length(client, &len);
    ESP_LOGI(TAG, "is_chunked:%d, chunk_length:%d, ret:%d", ret, len, err);
    } else {
    ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err));
    return -1;

    响应结果:
    I (30804) : HTTP GET Status = 200, content_length = -1
    I (30804) : is_chunked:1, chunk_length:0, ret:0