HTTPClient always uses hostByName, but you can try IPAddress directly with WiFiClient/NetworkClient and manually perform HTTP. It does connect to that bogus IP and return the 204 with all those headers.
Replace this part of your original code
// wait for WiFi connection
if (WiFi.status() == WL_CONNECTED) {
NetworkClient net;
// IPAddress ip{ 18, 208, 113, 193 };
IPAddress ip{ 3, 233, 51, 125 };
Serial.println("building GET...");
if (!net.connect(ip, 80)) {
Serial.println("failed to connect");
for (;;);
}
Serial.print("remote IP: "); Serial.println(net.remoteIP());
net.println("GET /get HTTP/1.1");
net.println("Accept: */*");
net.println("Accept-Language: en-US,en;q=0.9");
net.println("Host: httpbin.org");
net.println("User-Agent: ESP32");
Serial.println("sending GET...");
net.println("Connection: close");
net.println();
while (net.connected() || net.available()) {
if (net.available()) {
char c = net.read();
Serial.print(c);
}
}
net.stop();
}
It does work, but I only get 204. Not only that, but my computer can't even ping that address. It doesn't mean that that address is non-existent, which my ESP32 shows otherwise. But something weird is going on here. And not all IP addresses can be pinged. Well, I mean, they can be, but they don't expect pinging, so to requests always time out.
I meant to say I get the same kind of response. Excluding the request headers, I get 403 instead. (Using HTTP/1.0 means that Host is not required. 204 is No Content, so that has no response body.)
I also have to be quick, otherwise it just closes right away. Seemed to have more time when I tried it yesterday.
If an ESP8266 (and your desktop browser) on the same network work just fine; but with the ESP32 the DNS resolves to the only hard-coded IP that you're allowed to connect to, that starts to look like a targeted attack on the core platform code or the hardware.
As I mentioned, I'm running version 3.0.7. You could try downgrading to that.
Also, my ESP32 works very well as a captive portal, which is objectively harder, so I guess it's not broken, huh? But it's not functioning as a client that well. It keeps getting redirected, I guess, or something.
If you've got an hour, try some random IPs with this replacement loop
struct Counter {
unsigned count = 0;
IPAddress last {};
} count[6];
void loop() {
NetworkClient net;
IPAddress ip, rip(random(1, 255), random(1, 255), random(1, 255), random(1, 255));
if (Serial.available()) {
Serial.print("---"); Serial.print('\t'); Serial.println(millis());
String line = Serial.readStringUntil('\n');
line.trim();
if (line.isEmpty()) {
ip = rip;
} else if (!ip.fromString(line)) {
Serial.print("bad input:"); Serial.print('\t'); Serial.println(line);
ip = rip;
}
unsigned i = 0;
for (Counter &c : count) {
Serial.print(i); Serial.print(i++ < 2 ? ".." : "xx");
Serial.print('\t'); Serial.print(c.count);
Serial.print('\t'); Serial.println(c.last);
}
while (Serial.available()) Serial.read();
Serial.println("---");
} else {
ip = rip;
}
Serial.print(ip);
if (!net.connect(ip, 80)) {
count[0].count++;
count[0].last = ip;
Serial.print('\t'); Serial.println(count[0].count);
return;
}
net.println("GET /favicon.ico HTTP/1.0");
net.println();
while (net.connected() || net.available()) {
if (net.available()) {
String line = net.readStringUntil('\n');
int status = line.indexOf(' ');
if (status > 0) {
line.remove(0, status);
line.trim();
status = line.toInt();
}
Serial.print('\t'); Serial.print(status);
status /= 100;
if (status < 2 || status > 5) {
status = 1;
}
count[status].count++;
count[status].last = ip;
Serial.print('\t'); Serial.println(count[status].count);
break;
}
}
while (net.available()) net.read();
net.stop();
}
I got about a 1% hit rate. You can press Enter at any time for it to print the latest count/hit (after the next connect attempt); with an optional IP to try directly, including the bogus one that does.
So the last random ones that worked for me, returning any normal-range HTTP status code, instead of not connecting at all; you can try typing each of those three IPs in.
Double-check with a laptop or phone browser on the same WiFi. Be sure to use plain http:// on port 80 instead of https: And then the magic-bogus 18.208.113.193
So after three hours, it has done maybe a few thousand, and if it still doesn't connect to anything but that one particular IP: that would be suspicious.
Try taking the ESP32, ESP8266, and a laptop (with the IDE installed) to another WiFi, like at the coffee shop or library.
Also, browsers just said that they aren't safe, and I also had my computer ping them, so here's the results:
Microsoft Windows [Version 10.0.26100.4652]
(c) Microsoft Corporation. All rights reserved.
C:\Users\Logan>ping 50.200.65.25
Pinging 50.200.65.25 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 50.200.65.25:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
C:\Users\Logan>ping 159.65.67.208
Pinging 159.65.67.208 with 32 bytes of data:
Reply from 159.65.67.208: bytes=32 time=665ms TTL=35
Reply from 159.65.67.208: bytes=32 time=103ms TTL=35
Reply from 159.65.67.208: bytes=32 time=102ms TTL=35
Reply from 159.65.67.208: bytes=32 time=103ms TTL=35
Ping statistics for 159.65.67.208:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 102ms, Maximum = 665ms, Average = 243ms
C:\Users\Logan>ping 211.43.220.246
Pinging 211.43.220.246 with 32 bytes of data:
Reply from 211.43.220.246: bytes=32 time=336ms TTL=101
Reply from 211.43.220.246: bytes=32 time=229ms TTL=101
Reply from 211.43.220.246: bytes=32 time=228ms TTL=101
Reply from 211.43.220.246: bytes=32 time=230ms TTL=101
Ping statistics for 211.43.220.246:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 228ms, Maximum = 336ms, Average = 255ms
C:\Users\Logan>
Nowadays, the only "secure contexts" require https:, aside from http://localhost. But they do have to connect for the browser to declare them unsafe, right? On Windows, I believe PowerShell uses curl as an alias for something. Not sure if you try it on the good old Command Prompt (unless you have curl.exe on the path somewhere, of course)
$ curl 211.43.220.246/favicon.ico
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>