I'm attempting to get my Feather HUZZAH to connect with a server. I'm using the following code:
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(115200); //Serial connection
WiFi.begin("SSID", "WIFIPASS"); //WiFi connection
while (WiFi.status() != WL_CONNECTED) { //Wait for the WiFI connection completion
delay(500);
Serial.println("Waiting for connection");
}
}
void Auth3() {
HTTPClient http;
const char * headerkeys[] = {"system_user", "user_image", "user_id", "full_name", "sid"} ;
size_t headerkeyssize = sizeof(headerkeys)/sizeof(char*);
String PostData = "usr=email&pwd=password";
http.collectHeaders(headerkeys,headerkeyssize);
http.begin("http://1.2.3.4/api/method/login");
http.collectHeaders(headerkeys,headerkeyssize);
http.setReuse(true);
http.addHeader("Content-type", "application/x-www-form-urlencoded");
http.collectHeaders(headerkeys,headerkeyssize);
int code = http.POST(PostData);
Serial.printf("[HTTP] POST... code: %d\r\n", code);
Serial.println("TEST");
Serial.print(http.header("sid"));
String res = http.getString();
Serial.printf("Header count: %d\r\n", http.headers());
for (int i=0; i < http.headers(); i++) {
Serial.printf("%s = %s\r\n", http.headerName(i).c_str(), http.header(i).c_str());
}
Serial.printf("Res 1 = %s\r\n", res.c_str());
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
Auth3();
//delay(500);
//getRequest();
//delay(500);
} else {
Serial.println("Error in WiFi connection");
}
delay(30000); //Send a request every 30 seconds
}
I'm attempting to catch the cookie (header "sid"), but so far I'm not able to catch any headers. I'm not sure exactly how this is supposed to work, I've not seen any clear examples in my searches.
Any help is appreciated!