POST request doesn't work together with other codes

Hello! I'm doing my final paper on IT, basically it's a door unlocking with digital system build on Arduino Mega (2560) and futhermore there's a mobile app build with flutter framework. This app will show all information about some room.
So, I'm sending the fingerprintID from arduino to my web server (hosted on 000webhost) on json format ("id": fingerprintID). I did a lot of test to send a post request with a number and it had worked, but when i try to run all the code (sensor+servo motor+post request) together it didn't work...

here's my test_ethernet code, to run standalone:

#include <Ethernet.h>
#include <SPI.h>
#include <ArduinoJson.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS
EthernetClient client;
int id = 90;
char server[] = "analyseroom.000webhostapp.com";


void setup() {
  Serial.begin(9600);

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
  }

  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); 
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }
}

void loop() {

  const size_t capacity = JSON_OBJECT_SIZE(1);
  DynamicJsonDocument doc(capacity);

  doc["id"] = 101;

  serializeJson(doc, Serial);
  
  if (client.connect(server, 80)) {
    Serial.print("Connected to server on: ");
      Serial.println(client.remoteIP());
    client.println("POST /index.php HTTP/1.1");
    client.println("Host: analyseroom.000webhostapp.com"); // or generate from your server variable to not hardwire
    client.println("User-Agent: Arduino/Mega");
    client.println("Content-Type: application/json");
    client.println("Connection: close");
    client.print("Content-Length: ");
    client.println(measureJsonPretty(doc));
    client.println();
    serializeJsonPretty(doc, client);
  }
  Serial.println(client.connect(server, 80));
}

my main code:

#include "functions_&_InitStates.h"
#include <Ethernet.h>
#include <SPI.h>
#include <ArduinoJson.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS
EthernetClient client;
int id = 90;
char server[] = "analyseroom.000webhostapp.com";

void setup() {
  initSetup(); 
}

void loop() {
  getFingerprintIDez();
  open_close_door();
  
  if(post) {
    const size_t capacity = JSON_OBJECT_SIZE(1);
  DynamicJsonDocument doc(capacity);

  doc["id"] = fingerPrintID;

  serializeJson(doc, Serial);
  
  if (client.connect(server, 80)) {
    Serial.print("Connected to server on: ");
      Serial.println(client.remoteIP());
    client.println("POST /index.php HTTP/1.1");
    client.println("Host: analyseroom.000webhostapp.com"); 
    client.println("User-Agent: Arduino/Mega");
    client.println("Content-Type: application/json");
    client.println("Connection: close");
    client.print("Content-Length: ");
    client.println(measureJsonPretty(doc));
    client.println();
    serializeJsonPretty(doc, client);
  }
  Serial.println(client.connect(server, 80)); 
  post = false; 
  }
}

my functions_&_InitStates.h code:

#include <Adafruit_Fingerprint.h>
#include <Servo.h>

SoftwareSerial mySerial(10, 11);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

const int pinoServo = 8;
int fingerPrintID = 0;

Servo motor;
bool found = false, post = false;

void initSetup() {
  motor.attach(pinoServo); 

  Serial.begin(9600);
  while (!Serial);
  delay(100);
  Serial.println("\n\nTeste de autorização por digital!");
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) {
    Serial.println("Sensor reconhecido!");
  } else {
    Serial.println("Não foi possível encontrar o sensor :(");
    while (1) { delay(1); }
  }
  finger.getTemplateCount();
  Serial.print("Existem "); Serial.print(finger.templateCount); Serial.println(" templates no sensor!");
  Serial.println("Esperando por uma digital...");
}

void open_close_door() {
  if (found) {
    motor.write(128);
    post = true;
    found = false;
    delay(8000);
  }
  else {
    motor.write(45);
  }
}


uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Imagem tirada");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("Nenhuma digital detectada");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Erro de comunicação");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Erro na imagem");
      return p;
    default:
      Serial.println("Erro desconhecido");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Imagem convertida");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Imagem irreconhecível");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Erro de comunicação");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Informações da digital inexistentes");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Informações da digital inexistentes");
      return p;
    default:
      Serial.println("Erro desconhecido");
      return p;
  }
  
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Digital reconhecida!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Erro de comunicação");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Digital não reconhecida :(");
    return p;
  } else {
    Serial.println("Erro de comunicação");
    return p;
  }   
  
  // found a match!
  Serial.print("ID encontrado: #"); Serial.print(finger.fingerID); 
  Serial.print(" com número de série "); Serial.println(finger.confidence); 
  //found = true;
  //fingerPrintID = finger.fingerID;  
  return finger.fingerID;
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK) return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK) return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK) {
    Serial.println("Digital não válida!");
    found = false;
    return -1;
  }
  
  // found a match!
  Serial.print("ID encontrado: #"); Serial.print(finger.fingerID); 
  Serial.print(" com número de série "); Serial.println(finger.confidence);
  found = true;
  fingerPrintID = finger.fingerID;
  return finger.fingerID; 
}

Well why the ethernet code runs standalone, but when it is with the whole code it doesn't?

What hardware have you added to the mega to give it internet capability? Perhaps you have some hardware conflicts on the mega.

Well, I'm using the ethernet shield W5100. I'm trying to guess if it's a hardware or software conflicts, but no success...

Mdsp9070:
Well, I'm using the ethernet shield W5100. I'm trying to guess if it's a hardware or software conflicts, but no success...

You might check to see if you are using any of the W5100 pins are being used for other purposes. Also if an SD card is in the W5100, that can cause issues that need to be addressed.