Skip to content

how to unCompress gzip request with httpclient? #8908

@baloyou

Description

@baloyou

I need to make a GET request via "HTTPClient", but the data is GZIP compressed, how can I decompress it?

This code would have been normal.But the API was changed to gzip form, and the received content became garbled.

if (https.begin(client, "https://devapi.qweather.com/v7/weather/now?location=101070102&key=mykey")) {  // HTTPS
      Serial.print("[HTTPS] GET...\n");
      int httpCode = https.GET();

      if (httpCode > 0) {
        Serial.printf("[HTTPS] GET... code: %d\n", httpCode);

        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
          String payload = https.getString();
          Serial.println(payload);
        }
      } else {
        Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
      }
      
      https.end();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions