#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
String SSID = "Wokwi-GUEST", PASS = "";
void WiFiConnection();
void httpResponse();
void httpPost();
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
WiFiConnection();
// httpResponse();
httpPost();
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
void WiFiConnection() {
WiFi.begin(SSID.c_str(), PASS.c_str());
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("\nWiFi Connected!");
Serial.println(WiFi.localIP());
}
void httpResponse(){
HTTPClient http;
String host = "https://reqres.in/api/users";
String response;
http.begin(host);
http.GET();
response = http.getString();
Serial.println(response);
StaticJsonDocument<1024> JsonDoc;
deserializeJson(JsonDoc, response);
JsonObject JO = JsonDoc.as<JsonObject>();
String page = JO[String("page")];
Serial.println(page);
}
void httpPost(){
Serial.println("Posting!");
String HOST = "https://reqres.in/api/register";
HTTPClient http;
String response;
StaticJsonDocument<200> buff;
String JsonParams;
buff["email"] = "[email protected]";
buff["password"] = "pistol";
serializeJson(buff, JsonParams);
Serial.println(JsonParams);
http.begin(HOST);
http.addHeader("Content-Type", "application/json");
http.POST(JsonParams);
response = http.getString();
Serial.println(response);
while(http.POST(JsonParams) != 200){
Serial.println("Missing!");
}
Serial.println("Success!");
}