Can anyone get JSON from this link in the Arduino IDE via an ESP32 board? I'm curious as to why the link always fails even when opened through a normal browser. I want to get the latitude and longitude data from the website?
The point of that particular 301 Moved Permanently is that the resource is no longer available through the http protocol; you must use https, while everything else is the same.
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include "arduino_secrets.h"
WiFiClientSecure wifi;
HTTPClient http;
void setup() {
Serial.begin(115200);
WiFi.begin(SECRET_SSID, SECRET_PASS);
for (int i = 0; WiFi.status() != WL_CONNECTED; i++) {
Serial.print(i % 10 ? "." : "\n.");
delay(100);
}
Serial.println();
Serial.println(WiFi.localIP());
wifi.setInsecure(); // JUST TO PROVE IT WORKS
}
void loop() {
if (!http.begin(wifi, "https://nominatim.openstreetmap.org/search?q=Tangerang&format=json&addressdetails=1&limit=1")) {
Serial.println("http.begin failed");
} else {
auto status = http.GET();
if (status >= 200 && status < 300) {
Serial.println(http.getString());
} else {
Serial.print("GET failed, status: ");
Serial.println(status);
}
}
// delay(7500);
for (;;);
}