I've been trying to get the pokeapi to send back anything to me but i have no idea what im doing. i finally got some info back but its telling me that im structuring the get request wrong. im using an esp32. any ideas?
#include <WiFi.h>
#include <ArduinoHttpClient.h>
const char* ssid = "SSID";
const char* password = "PASSWORD";
char serverAddress[] = "pokeapi.co"; // server address
int port = 443;
WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
void setup() {
//initialize the serial port
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
//start the wifi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
delay(1000);
Serial.println("making GET request");
client.beginRequest();
client.get("/");
client.sendHeader("api/v2/pokemon");
client.endRequest();
// read the status code and body of the response
int statusCode = client.responseStatusCode();
String response = client.responseBody();
Serial.print("Status code: ");
Serial.println(statusCode);
Serial.print("Response: ");
Serial.println(response);
Serial.println("done");
}
void loop() {
}
and this is the response im getting
Status code: 400
Response: <html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>cloudflare</center>
</body>
</html>