i am trying to make a get request, read that request and make another request with that read value. i havent shown it in this code but i want to make a request inside in a request. is it possible to make a request without ending one, if its, how do i do that?
here is the code :
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#define WIFI_SSID "ssid"
#define WIFI_PASSWORD "pw"
void conn();
void getreq();
void anothergetreq();
void setup() {
conn();
getreq();
}
void loop() {
}
void getreq() {
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient http;
http.begin(*client, "https://jsonplaceholder.typicode.com/users/1");
int httpCode = http.GET();
String payaload = http.getString();
Serial.print("HTTP CODE: "); Serial.println(httpCode);
Serial.print("PAYLOAD: "); Serial.println(payaload);
//here i presume got the value from payload, and making another request with it
anothergetreq("posts/1");
http.end();
}
void anothergetreq(String p) {
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient http;
http.begin(*client, "https://jsonplaceholder.typicode.com/"+p);
int httpCode = http.GET();
String payaload = http.getString();
Serial.print("HTTP CODE: "); Serial.println(httpCode);
Serial.print("PAYLOAD: "); Serial.println(payaload);
http.end();
}
void conn() {
Serial.begin(9600);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
}
here is the output:
Connected with IP: 192.168.1.100
HTTP CODE: 200
PAYLOAD: {
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
}
HTTP CODE: -1
PAYLOAD: