Go Down

Topic: underscore in html address change to space (Read 99 times) previous topic - next topic


Dec 08, 2019, 11:52 am Last Edit: Dec 08, 2019, 01:23 pm by kolo987
I have a problem with a query to the server. Board ESP8266.
I need to download a json file. The server returns the "301 Moved Permanently" error when sending a
request (server, getservices)
Code: [Select]

String GETSERVICES = "/averageGET_SERVICES&hash=bnmmbb1";

void setup() {
  WiFi.begin(ssid, password);            
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

  int i = 0;
  while (WiFi.status() != WL_CONNECTED) {
      Serial.print(++i); Serial.print(' ');

  Serial.println("Connection established!");  
  Serial.print("IP address:\t");
  if (connect(server)){
  if(sendRequest(server, GETSERVICES) && skipResponseHeaders()) {
 Serial.println(client.readString()); // Here I get 301 error
  DynamicJsonDocument doc(1024);
  DeserializationError error = deserializeJson(doc, client);
    if (error) {
    Serial.print(F("deserializeJson() failed: "));

void loop() {
bool connect(String hostName) {
  Serial.print("Connect to ");

  bool ok = client.connect(hostName, 80);

  Serial.println(ok ? "Connected" : "Connection Failed!");
  return ok;
// Send the HTTP GET request to the server
bool sendRequest(String host, String resource) {
  Serial.print("GET ");

  client.print("GET ");
  client.println(" HTTP/1.1");
  client.print("Host: ");
  client.println("Connection: close");

  return true;

// Skip HTTP headers so that we are at the beginning of the response's body
bool skipResponseHeaders() {
  // HTTP headers end with an empty line
  char endOfHeaders[] = "\r\n\r\n";

  bool ok = client.find(endOfHeaders);

  if (!ok) {
      Serial.println("No response or invalid response!");
  return ok;

But getservices contains the string "xxxGET_SERVICESxxx" and "_" is replaced with space " ". This is probably a problem. What can I do with that?


I would not expect an _ to be turned into a space - but you have not posted code that reproduces this behavior, nor what board you're using and so on, so you haven't given us enough to provide more specific help. See the how to use this forum thread for information on how to post code so we can easily read it.

Also, please don't ignore the text at the top of the forum section that says that this section is not for questions about your project. This section is for IDE/board problems, not help with your project, I have asked the moderators to move your question to the appropriate section.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Go Up