I got a code here.(C++)
At the website: "github.com" the code works fine and I get the index of "meta" = 53
As soon as I change the address to for example "timeanddate.com", I get the index (-1) = no result.
My question: What is the difference between these two websites?
"meta" is included in both HTML source pages both are HTTPS What's missing?
Tests:
https://github.com = HTTP Status: 200 Index: 53.00
https://www.timeanddate.de = HTTP Status: 200 Index: -1.00
https://timeanddate.de = HTTP Status: 302
https://www.timeanddate.com = HTTP Status: 200 Index: -1.00
https://timeanddate.com = HTTP Status: 301 Index: -1.00
P.S. with google.com it even crashes
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecure.h>
#define SSID_NAME "XXXXXXXXXX"
#define SSID_PASSWORD "XXXXXXXXXX"
ESP8266WiFiMulti WiFiMulti;
//WiFiClientSecure client;
HTTPClient https;
BearSSL::WiFiClientSecure client;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFiMulti.addAP(SSID_NAME, SSID_PASSWORD);
//Connect to WIFI
Serial.print("Connecting to ");
Serial.print(SSID_NAME);
Serial.println(".");
Serial.print("Waiting for Wifi to connect...");
while (WiFiMulti.run() != WL_CONNECTED){
Serial.print(".");
delay(1000);
}
Serial.println(" Done.");
IPAddress ip(192,168,0,172);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
WiFi.config(ip, gateway, subnet);
}
void loop() {
int code = 0;
double bodyTag;
client.setInsecure();
client.setTimeout(8000);
https.begin(client,"https://www.google.com");
code = https.GET();
while (code != HTTP_CODE_OK){
Serial.print("HTTPCODE FAIL: ");
Serial.println(code);
code = https.GET();
delay(500);
}
Serial.print("HTTP Status: ");
Serial.println(code);
//Check if KeyWord is Found in Search.ch
bodyTag = https.getString().indexOf("meta");
Serial.print("Index: ");
Serial.println(bodyTag);
delay(5000);
}
Aucun commentaire:
Enregistrer un commentaire