• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

how i can retrive an url after code 302 on esp32

Q&A Forum › Category: ESP32 › how i can retrive an url after code 302 on esp32
0 Vote Up Vote Down
MELETIOS ROUSSIS asked 4 years ago

Parsing input failed!
HTTP Response code: 302
this mesage hapen when i try to get from url and this url serve another path url the problem is i cannot or i have not the expirien to found the new url if anybody can help
 
the code is bellow
 
/*
Rui Santos
Complete project details at Complete project details at https://RandomNerdTutorials.com/esp32-http-get-post-arduino/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <WiFi.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>
const char* ssid = “SSid”;
const char* password = “password”;
//Your Domain name with URL path or IP address with path
const char* serverName = “http://stream.radiojar.com/rbx9n33vdg0uv&#8221;; // the url i try
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;
String sensorReadings;
float sensorReadingsArr[3];
void setup() {
Serial.begin(115200);
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());

Serial.println(“Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.”);
}
void loop() {
//Send an HTTP POST request every 10 minutes
if ((millis() – lastTime) > timerDelay) {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){

sensorReadings = httpGETRequest(serverName);
Serial.println(sensorReadings);
JSONVar myObject = JSON.parse(sensorReadings);

// JSON.typeof(jsonVar) can be used to get the type of the var
if (JSON.typeof(myObject) == “undefined”) {
Serial.println(“Parsing input failed!”);
return;
}

Serial.print(“JSON object = “);
Serial.println(myObject);

// myObject.keys() can be used to get an array of all the keys in the object
JSONVar keys = myObject.keys();

for (int i = 0; i < keys.length(); i++) {
JSONVar value = myObject[keys[i]];
Serial.print(keys[i]);
Serial.print(” = “);
Serial.println(value);
sensorReadingsArr[i] = double(value);
}
Serial.print(“1 = “);
Serial.println(sensorReadingsArr[0]);
Serial.print(“2 = “);
Serial.println(sensorReadingsArr[1]);
Serial.print(“3 = “);
Serial.println(sensorReadingsArr[2]);
}
else {
Serial.println(“WiFi Disconnected”);
}
lastTime = millis();
}
}
String httpGETRequest(const char* serverName) {
WiFiClient client;
HTTPClient http;

// Your Domain name with URL path or IP address with 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;
}

Question Tags: mrs_melrou
5 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

What exactly are you trying to do when accessing this URL with your ESP32 board?

  • https://RandomNerdTutorials.com/esp32-http-get-post-arduino/

Regards,
Rui

2 Vote Up Vote Down
Steve Mercer answered 4 years ago

I believe you have a couple options here. Note that the following was gleaned from the HTTPClient.h file.
 
First (And probably easiest) is to force all redirects. After http.begin add a statement http.setFollowRedirects(2); I believe redirects are set to off normally.
 
Second, you could check the response headers using http.collectHeaders for a ‘Location’ header and do the redirect yourself. There is a tutorial that uses the 8266 but I believe the HTTPClient code is basically the same. You can see how the 302 response actually works.

0 Vote Up Vote Down
MELETIOS ROUSSIS answered 4 years ago

Mr Steve Mercer thank you for quik answer AFTER your instraction this i try to do it works i bild an internet radio (not finish yet) and the problem is some station have redirection in the end of septeber i finish so i post here the code for everybody . 
Rui Santos thank you for quik answer

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

Glad I could be of some help. Good luck with your project.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Great!
Thanks for helping, Steve.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.