Manejar web que incluye javaScript

Saludos a todos.
Tengo una placa esp8266 que se conecta como cliente a un servidor externo a través del una red wifi. Funciona.
Pero el servidor me devuelve una página que incluye una sección de javaScript. El servidor detecta que el cliente (en este caso la esp8266) no soporta javaScript y me redirige a una página de error. Aunque la info que necesito está en la sección estática de la página.

Consulta:
¿Puedo saltar ese chequeo de alguna manera?

Código:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

void setup() {

  Serial.begin(115200);
  delay(10);

  conectaWifi();
}


void loop() {

  // Send an HTTP GET request
  if ((millis() - lastTime) > timerDelay) {

    // Check WiFi connection status
    if(WiFi.status()== WL_CONNECTED){
      String serverPath = "ladireccion";
      
      String resultado = httpGETRequest(serverPath.c_str());
      Serial.println(resultado);

    } else {
      Serial.println("WiFi Disconnected");
      conectaWifi();
    }

    lastTime = millis();
  }
}

String httpGETRequest(const char* serverName) {
  WiFiClient client;
  HTTPClient http;
    
  // Your IP address with path or Domain name with URL path 
  http.begin(client, serverName);
  
  // Send HTTP POST request
  int httpResponseCode = http.GET();
  
  String payload = "{}"; 
  
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    payload = http.getString();
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }
  // Free resources
  http.end();

  return payload;
}

Soy nuevo y no se si he planteado bien la pregunta, o si la he colocado en el lugar adecuado. Disculpas de antemano.

Saludos!

You can't skip the detection on the server. It is likely based on the User-Agent header sent in the request. So you can just lie and say you're using a browser that supports JavaScript.

If you visit httpbin.org/headers, it will return all the request headers. For example

"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"

You can actually tell quite a bit about the browser and OS in use. There are also seemingly redundant or superseding claims. That's a result of how it evolved over thirty years.

HTTPClients vary in how to set the request headers. For ESP8266, their PostHTTPClient example shows calling addHeader immediately after begin. However, that function explicitly does not allow setting "User-Agent" that way, because it handles it separately, using the setUserAgent function. (It always sends one, unless it is empty, a zero-length string.)

You can use the string quoted above, or the one from whatever browser you have. If one of those works, you might even try to pare down the string to "Mozilla/5.0", or ""

Tu tema ha sido movido a la sección en español del foro. Utiliza el inglés en las secciones en inglés del foro.

Dónde esta la parte del código que incluye conectaWifi()?

Modiqué y agregué lo necesario con mi LAN y esto funciona

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "SSID";
const char* password = "password";

const unsigned long timerDelay = 5000;
unsigned long lastTime;

void conectaWifi() {
  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
}

void setup() {

  Serial.begin(115200);
  delay(10);

  conectaWifi();
}


void loop() {

  // Send an HTTP GET request
  if ((millis() - lastTime) > timerDelay) {

    // Check WiFi connection status
    if(WiFi.status()== WL_CONNECTED){
      String serverPath = "http://192.168.100.1/"; // mi router
      
      String resultado = httpGETRequest(serverPath.c_str());
      Serial.println(resultado);

    } else {
      Serial.println("WiFi Disconnected");
      conectaWifi();
    }

    lastTime = millis();
  }
}

String httpGETRequest(const char* serverName) {
  WiFiClient client;
  HTTPClient http;
    
  // Your IP address with path or Domain name with URL path 
  http.begin(client, serverName);
  
  // Send HTTP POST request
  int httpResponseCode = http.GET();
  
  String payload = "{}"; 
  
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    payload = http.getString();
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }
  // Free resources
  http.end();

  return payload;
}

Devolvió lo siguiente, bueno solo una parte posteo porque es enorme.

14:55:19.287 -> Connected to WiFi network with IP Address: 192.168.100.40
14:55:19.353 -> HTTP Response code: 200
14:55:19.450 -> <html>
14:55:19.450 -> <head>
14:55:19.450 -> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
14:55:19.450 -> <meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1"/>
14:55:19.450 -> <meta http-equiv="Pragma" content="no-cache" />
14:55:19.450 -> <title></title>
14:55:19.612 -> langDescList["chinese"] = "简体中文"; //or just '中文'?
14:55:19.612 -> langDescList["english"] = "English";
14:55:19.612 -> langDescList["japanese"] = "日本語";
14:55:19.612 -> langDescList["arabic"] = "العربية";
14:55:19.612 -> langDescList["portuguese"] = "Português";
14:55:19.612 -> langDescList["spanish"] = "Español";
14:55:19.612 -> langDescList["turkish"] = "turkish";
14:55:19.612 -> 
14:55:19.612 -> var languageSet = new Array();
14:55:19.644 -> 
14:55:19.644 -> if ((typeof languageList == 'string') && (languageList != ''))
14:55:19.644 -> languageSet = languageList.split("|");
14:55:19.644 -> 
14:55:19.644 -> if(Var_LastLoginLang == '')
14:55:19.644 -> {
14:55:19.644 -> Language = Var_DefaultLang;
14:55:19.644 -> }
14:55:19.644 -> else
14:55:19.644 -> {
14:55:19.644 -> Language = Var_LastLoginLang;
14:55:19.644 -> }
14:55:19.644 -> 
14:55:19.644 -> document.title = ProductName;
14:55:19.644 -> 
14:55:19.644 -> function genLanguageList()
14:55:19.644 -> {
14:55:19.644 -> if (languageList == '')
14:55:19.644 -> return false;
14:55:19.644 -> 
14:55:19.644 -> var ChangeLanguage = '';
14:55:19.644 -> 
14:55:19.644 -> if (languageSet.length > 1)
14:55:19.677 -> {

Hola, muchas gracias por la respuesta.
Si, conectaWifi() contiene ese codigo y funciona.
Mi sospecha es que la web solicita algún tipo de dato o acción al explorador sin el cual no me redirecciona a la página que solicito. ¿Puede ser correcto?
La web está alojada en un servidor gratuito, (infinityfree).
La respuesta que obtengo es esta:

22:19:19.360 -> HTTP Response code: 200
22:19:19.360 -> 
<html>
<body>
<script type="text/javascript" src="/aes.js" ></script>
<script>
function toNumbers(d){var e=[];
d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++) e+=(16>d[f]?"0":"")+d[f].toString(16);
return e.toLowerCase()}.
var a=toNumbers("f655ba9d09a112d4968c63579db590b4"), b=toNumbers("98344c2eee86c3994890592585b49f80"), c=toNumbers("1a02b3bc342529a22ea7236b229b307e");
document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; 
expires=Thu, 31-Dec-37 23:55:55 GMT; 
path=/";
location.href="http://makina.free.nf/consulta.php?i=1";
</script>
<noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support
</noscript>
</body>
</html>

Poné el sitio que querés consultar así comparo respuestas.
Es este?
location.href="http://makina.free.nf/consulta.php?i=1"

Si, http://makina.free.nf/consulta.php

Es un php sencillo que devuelve un objeto JSON.

Este es su código:

<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
?>

He preguntado en el foro del servidor y es un sistema de seguridad del servidor que no se puede deshabilitar.
Gracias de todos modos!!

Ahora no puedo pero intentaré una solución con lo que tienes. No dispongo de tiempo.
Se paciente, en unos dias lo veré o tal vez antes.

Como he comentado, el problema me ha surgido por esa politica del servisor que solo permite el acceso a exploradores que soporten javascript (para cuentas gratuitas de infinityfree).
He cambiado a otro servidor (awardspace) y ya accedo sin restricciones a los archivos.
Gracias por la respuesta.

Excelente!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.