Arduino Mega and ESP8266 - POST request

Hi

I'm collecting data from sensors and I want to save them to database. So i make in java API for saving data in database. I test that API in postman and everything works fine.
But it seems that i have some problem with arduino code in part where i send that POST request.
Can someone pls help me with that part:

#include <SoftwareSerial.h>
#include "cactus_io_AM2302.h"
#include <BMP280.h>

#define AM2302_PIN 2                                // definisanje pina 2 za AM2302 senzor
BMP280 bmp;
#define RX 10
#define TX 11
#define P0 1013.25
String AP = "xxxx";       // CHANGE ME
String PASS = "xxxxx"; // CHANGE ME

String API = "????";   // CHANGE ME
String HOST = "api.thingspeak.com";
String PORT = "80";

String Host = "192.168.0.87:8080" ;
String Url = "/e/api/environment_data/sendData" ;

int countTrueCommand;
int countTimeCommand; 
boolean found = false; 
int valSensor = 1;
SoftwareSerial esp8266(RX,TX); 
AM2302 dht(AM2302_PIN);                             // inicijalizacija senzora

//pocetne vrijednosti za senzor BMP280
double T = 0; 
double P = 0; 
char measure = 0;
float pritisak = 0;
 
  
void setup() {
  Serial.begin(9600);
  esp8266.begin(115200);
  sendCommand("AT",5,"OK");
  sendCommand("AT+CWMODE=1",5,"OK");
  sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
  
  //am2302(dht) senzor
  dht.begin();

  //BMP280 senzor
   if(!bmp.begin()) {             
    while(1);
    }
    bmp.setOversampling(4);
}
void loop() {
  //vrijednosti sa senzora AM2302
  dht.readHumidity();
  dht.readTemperature();
  
  if (isnan(dht.humidity) || isnan(dht.temperature_C)) {
    return;
  }
  float temperatura = dht.temperature_C;
  float vlaznost = dht.humidity;

  //vrijednost sa senzora MQ135
  float kvalitet_zraka = analogRead(0);

  //vrijednost sa senzora BMP280
  pritisak = collectData();


  //slanje podataka na thingspeak
  Serial.println("Sending data: " + String(temperatura));
  String urlfinal = "?temperature="+String(temperatura) + "&humidity=" + String(vlaznost) + "&airQuality=" + String(kvalitet_zraka) + "&pressure=" + String(pritisak);
  
  
  String Post = "POST " + Url + " HTTP/1.1\r\n" + 
  "Host: " + Host + "\r\n" + 
  "\r\n" +
  "Content-Type: application/x-www-form-urlencoded" +
  "Content-Length: " + urlfinal.length() + "\r\n" + urlfinal  ;
  sendCommand("AT+CIPMUX=1",5,"OK");
  sendCommand("AT+CIPSTART=0,\"TCP\",\""+ Host +"\","+ 8080,15,"OK"); 
  sendCommand("AT+CIPSEND=0," + String(Post.length()+4),4,">");
  esp8266.println(Post);
  Serial.println(Post);
  delay(30000);
  countTrueCommand++;
  sendCommand("AT+CIPCLOSE=0",5,"OK");
}

void sendCommand(String command, int maxTime, char readReplay[]) {
  while(countTimeCommand < (maxTime*1)) {
    esp8266.println(command);
    if(esp8266.find(readReplay)) {
      found = true;
      break;
    }
    countTimeCommand++;
  }
  
  if(found == true) {
    countTrueCommand++;
    countTimeCommand = 0;
  }
  
  if(found == false) {
    countTrueCommand = 0;
    countTimeCommand = 0;
  }
  found = false;
}

float collectData() {
  measure = bmp.startMeasurment();
  if(measure != 0) {
    delay(measure);
    measure = bmp.getTemperatureAndPressure(T, P);
    if(measure != 0) {
      P = P + 17;
      T = T - 0.8; 
      return P;
      delay(30000);
    }
    else
      return 0;
  }
  else
    return 0;
}

I println Post in serial monitore and this is how it looks:

POST /e/api/environment_data/sendData HTTP/1.1
Host: 192.168.0.27:8080
 
Content-Type: application/x-www-form-urlencodedContent-Length: 67
?temperature=27.60&humidity=59.70&airQuality=37.00&pressure=1002.39

I've also checked connection of wifi module and it's also ok, because it saves data to thingspeak, but when i try to save data to localhost database it's not working.

the empty line should be after http headers. content-length is a header

I've just try that and move empty line after http headers but still nothing happens.

you should print the http response or esp8266 error message

can you pls tell me how can i print http response or error?

javax05:
can you pls tell me how can i print http response or error?

by printing everything recieved from the esp8266

in your title you ay you use a Mega, then why would you use

#include <SoftwareSerial.h>
SoftwareSerial esp8266(RX,TX);

and did you know that reception for swSerial at this speedesp8266.begin(115200);is unreliable.
Either way the method of giving orders to an ESP using AT commands from an Arduino is so much more cumbersome than programming the ESP unit directly to do what you want it to do and communicating using a method from Serial Input Basics
Thogh i suppose for small 'proof of concept' you may get the result you want.