Multiple If in Android Browser vs PC Browser

Hello community!

First of all thank you all for this incredible "manual" each of you have contributed which has help me ease into the Arduino world and really do the things i need fast and reliable!

I have encountered a nitpick issue with my program which i would love your input.

I am sending json (POSTcall function) through the Arduino's API to a website and the bellow function is used to get the input from the URL:

void process(BridgeClient client) {
  // read the command
  String command = client.readStringUntil('\r');

  // is this API of valid string?
  if ((command == "possition") || (command == "up") || (command == "down")) {
    if ((command == "possition") && (possition == 1)) {
      POSTcall(client, "Up");
      return;
    }
    else if ((command == "possition") && (possition == 2)) {
      POSTcall(client, "Down");
      return;
    }
    else if ((command == "up") && (possition == 2) ) {
      buttonUPpressed(client);
      return;
    }
    else if ((command == "down") && (possition == 1)) {
      buttonDOWNpressed(client);
      return;
    }
    else {
      switch (possition) {
        case 1:
          POSTcall(client, "The keys are allready Up!");
          break;
        case 2:
          POSTcall(client, "The Keys are allready Down!");
          break;
      }
    }
    return;
  }
  else {
    POSTcall(client, "An error occurred");
    return;
  }

  delay(1);
  return;
}

POSTcall Function:

void POSTcall (BridgeClient client, const char* state) {
  client.println("Status: 200");
  client.println("Access-Control-Allow-Headers: *");
  client.println("Access-Control-Allow-Origin: http://tsekadoros.ddns.net");
  client.println("Access-Control-Allow-Methods: POST");
  client.println("Content-type: application/json; charset=utf-8");
  client.println(); //mandatory blank line
  client.print("{\"Position\": \"");
  client.print(state);
  client.print("\"}");
}

Everything works as expected on Mozilla and Chrome on 2 PCs that ive tried but when i sent the "Up" or "Down" api from my Galaxy s8+ chrome browser i get the "The keys are allready Up!" or "The keys are allready Down!" values depending if it was the down or up button.

Is there maybe an explanation to this? Maybe i missed a "return" somewhere in the function?

Thank you!

May be it’s google or Samsung stealing your data for advertising purpose... who knows - as we can’t see the code...

—> Don’t post snippets... we have no clue what is modifying the variable possition for example... (which would probably be better spelled as po[b][color=blue]s[/color][/b]ition by the way)

use Content-length header

It is common practice in Arduino sketches to not to send the Content-length header with HTTP responses and POST requests. In most cases it is because when the HTTP headers are send, the size of data is not known. The browser or WebServer then doesn't know if it received all the data and waits until the connection is closed or timeout is reached. It leads to long time until the page is shown in browser or long time until a Web Server sends the response to requesting Arduino sketch.