简体   繁体   中英

How to issue GET request to Google from an ESP32? (can't get it to work)

I´m trying to get an ESP32 to send GET requests to Google, but all I get is a -1 error response from the server. I'm using the Arduino IDE for this.

Based on that I will then need to modify it so that it sends a GET to our company's application running on App Engine.

if(WiFi.status()== WL_CONNECTED){
  HTTPClient http;

        
  // Domain name with URL path or IP address with path
  http.begin("google.com");
  
  // Send HTTP GET request
  int httpResponseCode = http.GET();
  
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    String payload = http.getString();
    Serial.println(payload);
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }
  // Free resources
  http.end();
}
else {
  Serial.println("WiFi Disconnected");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM